fix: 桌面端新窗口打开任务无法发起聊天的问题

This commit is contained in:
kuaifan 2023-02-25 22:09:41 +08:00
parent bdbc394b4a
commit 9a12184f9b
4 changed files with 9 additions and 10 deletions

2
cmd
View File

@ -135,7 +135,7 @@ run_electron() {
else
mkdir -p ./electron/public
cp ./electron/index.html ./electron/public/index.html
npx vite build -- fromcmd electron
npx vite build -- fromcmd electronBuild
fi
node ./electron/build.js $argv
}

2
electron/build.js vendored
View File

@ -193,7 +193,7 @@ function startBuild(data, publish, release) {
if (["dev"].includes(argv[2])) {
// 开发模式
fs.writeFileSync(devloadCachePath, utils.formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8');
child_process.spawn("npx", ["vite", "--", "fromcmd", "electron"], {stdio: "inherit"});
child_process.spawn("npx", ["vite", "--", "fromcmd", "electronDev"], {stdio: "inherit"});
child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"});
} else if (["app"].includes(argv[2])) {
// 编译给app

View File

@ -50,6 +50,9 @@ contextBridge.exposeInMainWorld(
sendMessage: function (action, args) {
ipcRenderer.send(action, args);
},
sendSyncMessage: function (action, args) {
ipcRenderer.sendSync(action, args)
},
listenOnce: function (action, callback) {
ipcRenderer.once(action, function (event, args) {
callback(args);

12
vite.config.js vendored
View File

@ -7,11 +7,10 @@ import vitePluginFileCopy from 'vite-plugin-file-copy';
import autoprefixer from 'autoprefixer';
const argv = process.argv;
const isCmd = argv.includes('fromcmd');
const isElectron = argv.includes('electron');
const publicPath = isElectron ? 'electron/public' : 'public';
const basePath = argv.includes('electronBuild') ? './' : '/';
const publicPath = argv.includes('electronBuild') ? 'electron/public' : 'public';
if (!isCmd) {
if (!argv.includes('fromcmd')) {
spawnSync("npx", [resolve(__dirname, 'cmd'), argv.includes("build") ? "build" : "dev"], {stdio: "inherit"});
process.exit()
}
@ -22,7 +21,7 @@ export default defineConfig(({command, mode}) => {
const port = parseInt(env['APP_DEV_PORT'])
return {
base: isElectron ? './' : '/',
base: basePath,
publicDir: publicPath,
server: {
host,
@ -39,9 +38,6 @@ export default defineConfig(({command, mode}) => {
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
define: {
'process.env.NODE_ENV': command === 'serve' ? '"development"' : '"production"',
},
build: {
manifest: true,
outDir: publicPath,