From 09f7eefe31aa5bd58b0761bd9d3b5d8cc1329136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E5=BF=97=E8=B6=85?= Date: Thu, 20 Jul 2023 12:12:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E2=80=9C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=AA=8C=E8=AF=81=E5=8A=9F=E8=83=BD=E2=80=9D?= =?UTF-8?q?=E5=9C=A8=E7=94=9F=E4=BA=A7=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - src/main/app.ts | 91 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index e05042e..e474478 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/main/app.ts b/src/main/app.ts index 5e5d11e..4c74eff 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -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) { - createWindow() - - // 屏蔽 F11 进入/退出全屏功能 - globalShortcut.register('F11', () => {return}) + 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() + } + }) } else { dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员') - app.quit() + process.exit(1) } -}) +} -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - } -}) - -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) +main();