Initial commit: Receipt Studio desktop application
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
import { createServer } from 'vite'
|
||||
import { build } from 'esbuild'
|
||||
import electron from 'electron'
|
||||
const args=process.argv.slice(2),smoke=args.includes('--smoke-test')
|
||||
console.log('正在准备收据工坊的本地开发窗口…')
|
||||
for (const entry of ['index', 'preload']) await build({ entryPoints: ['src/main/'+entry+'.ts'], outfile: 'dist/main/'+entry+'.cjs', bundle: true, platform: 'node', format: 'cjs', external: ['electron'], sourcemap:true })
|
||||
const server = await createServer(); await server.listen()
|
||||
const env={ ...process.env, ELECTRON_RENDERER_URL: 'http://127.0.0.1:5173' }
|
||||
delete env.ELECTRON_RUN_AS_NODE
|
||||
const child = spawn(electron, ['.',...args], { stdio: 'inherit', windowsHide: smoke, env })
|
||||
let closing=false
|
||||
async function close(code=0){
|
||||
if(closing)return;closing=true
|
||||
if(child.exitCode===null)child.kill()
|
||||
await server.close()
|
||||
process.exit(code)
|
||||
}
|
||||
child.on('error',error=>{console.error('无法启动桌面程序:',error.message);void close(1)})
|
||||
child.on('exit',code=>void close(code??0))
|
||||
process.on('SIGINT',()=>void close())
|
||||
process.on('SIGTERM',()=>void close())
|
||||
console.log('请在自动打开的“收据工坊”桌面窗口中操作,按 F12 打开调试工具。')
|
||||
console.log('界面修改会自动更新;主程序修改后请关闭并重新启动。')
|
||||
if(smoke)setTimeout(()=>void close(),8000).unref()
|
||||
Reference in New Issue
Block a user