2023-07-19 10:56:45 +08:00
|
|
|
import { app, globalShortcut, BrowserWindow, dialog } from 'electron'
|
2023-07-20 12:12:32 +08:00
|
|
|
import { join } from 'path'
|
2023-07-19 10:56:45 +08:00
|
|
|
|
2023-07-20 12:12:32 +08:00
|
|
|
const child_process = require('child_process')
|
|
|
|
|
|
|
|
|
|
function queryKeys(keyPath: string, value: string) {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
try {
|
|
|
|
|
child_process.exec(`reg query ${keyPath} /v ${value}`, (error: Error, stdout: string, stderr: string) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
resolve({stdout, stderr});
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reject(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const keyPath = 'HKEY_CURRENT_USER\\SOFTWARE\\HwaSmart'
|
|
|
|
|
const value = 'global-navigation-satellite-system'
|
2023-07-19 10:56:45 +08:00
|
|
|
async function checkLaunchEnv() {
|
2023-07-20 12:12:32 +08:00
|
|
|
try {
|
|
|
|
|
const result: any = await queryKeys(keyPath, value);
|
|
|
|
|
// console.log('stdout', result.stdout);
|
|
|
|
|
return true
|
|
|
|
|
// 成功
|
|
|
|
|
// 查询到 有这个app启动项
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// 没有查询到该app启动项目
|
|
|
|
|
// console.log('error :>> ', error);
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-07-19 10:56:45 +08:00
|
|
|
}
|
2021-09-14 07:31:59 +08:00
|
|
|
|
2023-07-20 12:12:32 +08:00
|
|
|
|
|
|
|
|
|
2021-09-14 07:31:59 +08:00
|
|
|
function createWindow() {
|
2021-12-09 15:06:40 +08:00
|
|
|
const win = new BrowserWindow({
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
frame: false,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
nodeIntegration: true,
|
|
|
|
|
preload: join(__dirname, 'preload.js')
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-09-14 07:31:59 +08:00
|
|
|
|
2021-12-09 15:06:40 +08:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
|
win.loadURL('http://localhost:3000/')
|
|
|
|
|
win.webContents.openDevTools()
|
|
|
|
|
} else {
|
|
|
|
|
win.loadFile('dist/render/index.html')
|
|
|
|
|
}
|
2021-09-14 07:31:59 +08:00
|
|
|
}
|
|
|
|
|
|
2023-07-20 12:12:32 +08:00
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
// 异步代码
|
|
|
|
|
const checkReault: any = await checkLaunchEnv()
|
|
|
|
|
console.log('env right:', checkReault);
|
|
|
|
|
|
|
|
|
|
// 异步代码执行完毕后执行的代码
|
2023-07-19 10:56:45 +08:00
|
|
|
if (checkReault) {
|
2023-07-20 12:12:32 +08:00
|
|
|
app.whenReady().then(async () => {
|
|
|
|
|
|
|
|
|
|
createWindow()
|
|
|
|
|
|
|
|
|
|
// 屏蔽 F11 进入/退出全屏功能
|
|
|
|
|
globalShortcut.register('F11', () => {return})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
|
app.quit()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
|
createWindow()
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-19 10:56:45 +08:00
|
|
|
} else {
|
|
|
|
|
dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员')
|
2023-07-20 12:12:32 +08:00
|
|
|
process.exit(1)
|
2021-12-09 15:06:40 +08:00
|
|
|
}
|
2023-07-20 12:12:32 +08:00
|
|
|
}
|
2021-09-14 07:31:59 +08:00
|
|
|
|
2023-07-20 12:12:32 +08:00
|
|
|
main();
|