Skip to content

Commit

Permalink
build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
caorushizi committed Jan 14, 2024
1 parent ad1003b commit c9be688
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion packages/main/plugin/src/App.scss
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/main/plugin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function App() {
trigger={["click"]}
>
<FloatButton
className="app-float-button"
icon={<img className="app-logo" src={logo} alt="" />}
shape="square"
badge={{
Expand Down
34 changes: 19 additions & 15 deletions packages/main/src/helper/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 =
Expand Down
13 changes: 9 additions & 4 deletions packages/main/src/services/WebviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand Down
21 changes: 21 additions & 0 deletions scripts/build-server.mjs
Original file line number Diff line number Diff line change
@@ -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}`;

0 comments on commit c9be688

Please sign in to comment.