From f2a0ed72190f0e040d2ee1ed6393f857ad7c9f3a Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sun, 3 Mar 2024 07:04:17 +0800 Subject: [PATCH] fix the path of EditThisCookie zip file while run launch-bosszhipin-login-page-with-preload-extension from ui --- .../index.mjs | 18 ++++++++++++++++-- packages/ui/electron-builder.yml | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs b/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs index 0039733..35c7df2 100644 --- a/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs +++ b/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs @@ -14,6 +14,7 @@ import os from 'node:os' import path from 'node:path'; import JSON5 from 'json5' import url from 'url'; +import packageJson from './package.json' assert {type: 'json'} const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) @@ -32,15 +33,28 @@ if (!fs.existsSync( if (!fs.existsSync(extensionDir)) { fs.mkdirSync(extensionDir) } -const editThisCookieZipPath = path.join(__dirname, 'extensions', 'EditThisCookie.zip') const editThisCookieExtensionPath = path.join(extensionDir, 'EditThisCookie') +let editThisCookieZipPath +async function getEditThisCookieZipPath () { + if (editThisCookieZipPath) { + return editThisCookieZipPath + } + if (isRunFromUi) { + const { app } = await import('electron') + editThisCookieZipPath = path.join(app.getAppPath(), './node_modules', packageJson.name, 'extensions', 'EditThisCookie.zip') + } else { + editThisCookieZipPath = path.join(__dirname, 'extensions', 'EditThisCookie.zip') + } + return editThisCookieZipPath +} + export async function main() { if (!fs.existsSync( path.join(editThisCookieExtensionPath, 'manifest.json') )) { await extractZip( - editThisCookieZipPath, + await getEditThisCookieZipPath(), { dir: extensionDir } diff --git a/packages/ui/electron-builder.yml b/packages/ui/electron-builder.yml index 5db0d74..599db3f 100644 --- a/packages/ui/electron-builder.yml +++ b/packages/ui/electron-builder.yml @@ -10,7 +10,8 @@ files: - '!{.env,.env.*,.npmrc,pnpm-lock.yaml}' - '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}' asarUnpack: - - resources/** + - 'resources/**' + - 'node_modules/@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension/**' extraResources: - external-node-runtime-dependencies/** win: