diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ac6621f1..3a3cce57 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,7 @@ version: 2 updates: - - package-ecosystem: "" # See documentation for possible values + - package-ecosystem: "npm" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "weekly" diff --git a/package.json b/package.json index 3f9ab5dc..99023b34 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build:plugin": "pnpm -F plugin run build", "build:main": "pnpm -F main run build", "build:renderer": "pnpm -F renderer run build", - "build:server": "cd internal && cross-env GIN_MODE=release go build -o ../packages/main/bin/win32/server.exe", + "build:server": "zx scripts/build-server.mjs", "pack": "pnpm -F media-downloader run pack", "release": "pnpm run build && pnpm -F main run release", "docs:dev": "vitepress dev docs", diff --git a/packages/main/plugin/src/App.scss b/packages/main/plugin/src/App.scss index 31faaa15..e291e6f7 100644 --- a/packages/main/plugin/src/App.scss +++ b/packages/main/plugin/src/App.scss @@ -1,6 +1,12 @@ #MediagoRoot { + position: absolute; + z-index: 99999; .app { - z-index: 9999; + z-index: 99999; + .app-float-button { + left: 30px; + bottom: 30px; + } .app-logo { display: block; box-sizing: border-box; diff --git a/packages/main/plugin/src/App.tsx b/packages/main/plugin/src/App.tsx index 1f2d0a3c..bcc55e42 100644 --- a/packages/main/plugin/src/App.tsx +++ b/packages/main/plugin/src/App.tsx @@ -54,6 +54,7 @@ function App() { trigger={["click"]} > } shape="square" badge={{ diff --git a/packages/main/src/helper/variables.ts b/packages/main/src/helper/variables.ts index ddda69be..487a0659 100644 --- a/packages/main/src/helper/variables.ts +++ b/packages/main/src/helper/variables.ts @@ -6,10 +6,21 @@ const appPath = app.getAppPath(); export const appData = app.getPath("appData"); export const download = app.getPath("downloads"); +export const isMac = process.platform === "darwin"; +export const isWin = process.platform === "win32"; + if (!isDev) { global.__bin__ = resolve(appPath, "../bin"); } +export function resolveStatic(path: string) { + const relativePath = isDev ? "../.." : ".."; + return resolve(appPath, relativePath, path); +} +export function resolveBin(path: string) { + return resolve(__bin__, path); +} + export const appName = process.env.APP_NAME || "electron-template"; export const workspace = resolve(appData, appName); export const defaultScheme = "mediago"; @@ -18,24 +29,17 @@ export const PERSIST_WEBVIEW = "persist:webview"; export const db = resolve(workspace, "app.db"); // bin path -export const ffmpegPath = resolve(__bin__, "ffmpeg"); -export const biliDownloaderBin = resolve(__bin__, "BBDown"); -export const m3u8DownloaderBin = - process.platform === "win32" - ? resolve(__bin__, "N_m3u8DL-CLI") - : resolve(__bin__, "N_m3u8DL-RE"); -export const videoServerBin = resolve(__bin__, "server.exe"); +export const ffmpegPath = resolveBin("ffmpeg"); +export const biliDownloaderBin = resolveBin("BBDown"); +const downloaderBinName = isWin ? "N_m3u8DL-CLI" : "N_m3u8DL-RE"; +export const m3u8DownloaderBin = resolveBin(downloaderBinName); +export const videoServerBin = resolveBin("server"); // mobile path -export const mobilePath = resolve( - appPath, - isDev ? "../../mobile" : "../mobile" -); +export const mobilePath = resolveStatic("mobile"); // plugin path -export const pluginPath = resolve( - appPath, - isDev ? "../../plugin" : "../plugin" -); +export const pluginPath = resolveStatic("plugin/index.js"); +export const pluginStylePath = resolveStatic("plugin/style.css"); // user agent export const pcUA = diff --git a/packages/main/src/services/WebviewService.ts b/packages/main/src/services/WebviewService.ts index ef4e4e94..99530642 100644 --- a/packages/main/src/services/WebviewService.ts +++ b/packages/main/src/services/WebviewService.ts @@ -3,7 +3,13 @@ import { DownloadType } from "../interfaces"; import { inject, injectable } from "inversify"; import { TYPES } from "../types"; import isDev from "electron-is-dev"; -import { PERSIST_WEBVIEW, mobileUA, pcUA } from "../helper"; +import { + PERSIST_WEBVIEW, + mobileUA, + pcUA, + pluginPath, + pluginStylePath, +} from "../helper"; import { ElectronBlocker } from "@cliqz/adblocker-electron"; import fetch from "cross-fetch"; import path from "path"; @@ -71,8 +77,7 @@ const filterList: SourceFilter[] = [ }, ]; -const preloadPath = path.resolve(__dirname, "../../plugin/style.css"); -const styleText = readFileSync(preloadPath, "utf-8"); +const styleText = readFileSync(pluginStylePath, "utf-8"); // FIXME: 需要重构 @injectable() @@ -103,7 +108,7 @@ export default class WebviewService { this.view = new BrowserView({ webPreferences: { partition: PERSIST_WEBVIEW, - preload: path.resolve(__dirname, "../../plugin/index.js"), + preload: pluginPath, }, }); this.view.setBackgroundColor("#fff"); diff --git a/scripts/build-server.mjs b/scripts/build-server.mjs new file mode 100644 index 00000000..c8f1da8f --- /dev/null +++ b/scripts/build-server.mjs @@ -0,0 +1,21 @@ +#!/usr/bin/env zx + +const platform = os.platform(); + +let GOOS = ""; +let GOARCH = "amd64"; +let filename = "../packages/main/bin/win32/server"; + +if (platform == "linux") { + GOOS = "linux"; +} else if (platform == "darwin") { + GOOS = "darwin"; +} else if (platform == "win32") { + GOOS = "windows"; + filename += ".exe"; +} else { + console.error(`Unsupported OS: ${platform}`); + process.exit(1); +} + +await $`cd internal && npx cross-env GIN_MODE=release GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${filename}`;