|
1 | | -const { app } = require('electron'); |
| 1 | +const { app } = require('electron'); |
2 | 2 | // yf add |
3 | | -const { BrowserWindow } = require('electron') |
| 3 | +const { BrowserWindow, dialog, shell } = require('electron') |
4 | 4 |
|
5 | 5 | const fs = require('fs'); |
6 | 6 | const path = require('path'); |
7 | 7 | const process = require('child_process').spawn; |
8 | 8 | const portfinder = require('detect-port'); |
9 | 9 | let io, browserWindows, ipc, apiProcess, loadURL; |
10 | | -let appApi, menu, dialog, notification, tray, webContents; |
11 | | -let globalShortcut, shell, screen, clipboard; |
| 10 | +let appApi, menu, dialogApi, notification, tray, webContents; |
| 11 | +let globalShortcut, shellApi, screen, clipboard; |
12 | 12 |
|
13 | 13 | // yf add |
14 | 14 | let loadingWindow; |
15 | 15 | let mainWindowId; |
| 16 | +let countDownInterval; |
16 | 17 |
|
17 | 18 | // yf add |
18 | 19 | const manifestJsonFile = require("./bin/electron.manifest.json"); |
@@ -52,12 +53,12 @@ function startSocketApiBridge(port) { |
52 | 53 | browserWindows = require('./api/browserWindows')(socket); |
53 | 54 | ipc = require('./api/ipc')(socket); |
54 | 55 | menu = require('./api/menu')(socket); |
55 | | - dialog = require('./api/dialog')(socket); |
| 56 | + dialogApi = require('./api/dialog')(socket); |
56 | 57 | notification = require('./api/notification')(socket); |
57 | 58 | tray = require('./api/tray')(socket); |
58 | 59 | webContents = require('./api/webContents')(socket); |
59 | 60 | globalShortcut = require('./api/globalShortcut')(socket); |
60 | | - shell = require('./api/shell')(socket); |
| 61 | + shellApi = require('./api/shell')(socket); |
61 | 62 | screen = require('./api/screen')(socket); |
62 | 63 | clipboard = require('./api/clipboard')(socket); |
63 | 64 | }); |
@@ -114,13 +115,45 @@ function startLoadingWindow() { |
114 | 115 | loadingWindow.loadURL(loadingUrl); |
115 | 116 | loadingWindow.once('ready-to-show', () => { |
116 | 117 | loadingWindow.show() |
| 118 | + |
| 119 | + // 激活倒计时 |
| 120 | + activeCountDowInterval(manifestJsonFile) |
117 | 121 | }) |
118 | 122 | loadingWindow.on('closed', () => { |
119 | 123 | loadingWindow = null |
| 124 | + |
| 125 | + clearInterval(countDownInterval) |
120 | 126 | }) |
121 | 127 | } |
122 | 128 | } |
123 | 129 |
|
| 130 | +function activeCountDowInterval(manifestJsonFile) { |
| 131 | + if (!manifestJsonFile.timeout || !manifestJsonFile.timeout.limit) |
| 132 | + return |
| 133 | + |
| 134 | + let limitSecond = manifestJsonFile.timeout.limit |
| 135 | + let currentSecond = 0; |
| 136 | + countDownInterval = setInterval(() => { |
| 137 | + currentSecond++; |
| 138 | + if (currentSecond < limitSecond) |
| 139 | + return; |
| 140 | + |
| 141 | + clearInterval(countDownInterval); |
| 142 | + |
| 143 | + dialog.showMessageBox(loadingWindow, { |
| 144 | + type: 'error', |
| 145 | + buttons: ["前往安装"], |
| 146 | + title: '文件缺失提示', |
| 147 | + message: '计算机缺少组件无法启动该程序,点击前往安装组件后重试', |
| 148 | + }, (res, isChecked) => { |
| 149 | + if (manifestJsonFile.timeout.help) |
| 150 | + shell.openExternal(manifestJsonFile.timeout.help) |
| 151 | + app.quit(); |
| 152 | + }); |
| 153 | + |
| 154 | + }, 1000) |
| 155 | +} |
| 156 | + |
124 | 157 | //app.on('activate', () => { |
125 | 158 | // On macOS it's common to re-create a window in the app when the |
126 | 159 | // dock icon is clicked and there are no other windows open. |
|
0 commit comments