修复“添加启动验证功能”在生产模式下不能正常工作的问题
parent
fc337e951d
commit
09f7eefe31
|
@ -13,7 +13,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"cesium": "^1.88.0",
|
||||
"regedit": "^5.1.2",
|
||||
"vue": "^3.2.26",
|
||||
"vue-cesium": "^3.0.4",
|
||||
"vuex": "^4.0.1"
|
||||
|
|
|
@ -1,15 +1,42 @@
|
|||
import { app, globalShortcut, BrowserWindow, dialog } from 'electron'
|
||||
import { join } from "path"
|
||||
import { promisified as regedit } from 'regedit'
|
||||
// const regedit = require('regedit').promisified
|
||||
import { join } from 'path'
|
||||
|
||||
const REG_DIR_PATH:string[] = ['HKCU\\SOFTWARE\\HwaSmart']
|
||||
async function checkLaunchEnv() {
|
||||
const result = await regedit.list(REG_DIR_PATH)
|
||||
// console.log(result[REG_DIR_PATH[0]].exists)
|
||||
return result[REG_DIR_PATH[0]].exists
|
||||
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'
|
||||
async function checkLaunchEnv() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
fullscreen: true,
|
||||
|
@ -28,27 +55,37 @@ function createWindow() {
|
|||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
const checkReault = await checkLaunchEnv()
|
||||
|
||||
async function main() {
|
||||
// 异步代码
|
||||
const checkReault: any = await checkLaunchEnv()
|
||||
console.log('env right:', checkReault);
|
||||
|
||||
// 异步代码执行完毕后执行的代码
|
||||
if (checkReault) {
|
||||
app.whenReady().then(async () => {
|
||||
|
||||
createWindow()
|
||||
|
||||
// 屏蔽 F11 进入/退出全屏功能
|
||||
globalShortcut.register('F11', () => {return})
|
||||
} else {
|
||||
dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员')
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
Loading…
Reference in New Issue