|
17 | 17 | const DEBUG = false |
18 | 18 | const port = 3000 |
19 | 19 |
|
20 | | -import * as Fs from 'fs' |
21 | | -import * as Os from 'os' |
22 | | -import { join, resolve, basename } from 'path' |
23 | | -import * as freePort from 'portastic' |
| 20 | +import { join } from 'path' |
24 | 21 | import { format } from 'url' |
25 | | -import { spawn } from 'child_process' |
26 | | -import * as path from 'path' |
27 | | -import * as Crypto from 'crypto' |
28 | 22 |
|
29 | 23 | const { app, BrowserWindow, Tray, Menu, dialog, autoUpdater, desktopCapturer, shell } = require ( 'electron' ) |
30 | 24 |
|
@@ -113,84 +107,12 @@ if ( makeSingleInstance ()) { |
113 | 107 | // squirrel event handled and app will exit in 1000ms, so don't do anything else |
114 | 108 | const version = app.getVersion() |
115 | 109 |
|
116 | | -enum lang { 'zh', 'ja', 'en', 'tw' } |
117 | | - |
118 | | -let isSingleInstanceCheck = true |
119 | 110 | let localServer1 = null |
120 | 111 |
|
121 | 112 | let tray = null |
122 | 113 | let mainWindow = null |
123 | 114 | let doReady = false |
124 | 115 |
|
125 | | -const hideWindowDownload = ( downloadUrl, saveFilePath, Callback ) => { |
126 | | - let _err = null |
127 | | - if ( !downloadUrl ) { |
128 | | - return Callback ( new Error ( 'no url' )) |
129 | | - } |
130 | | - Fs.access ( saveFilePath, err => { |
131 | | - if ( ! err ) { |
132 | | - return Callback () |
133 | | - } |
134 | | - |
135 | | - let win = new BrowserWindow ({ show: DEBUG }) |
136 | | - DEBUG ? win.webContents.openDevTools() : null |
137 | | - //win.maximize () |
138 | | - //win.setIgnoreMouseEvents ( true ) |
139 | | - |
140 | | - let startTime = 0 |
141 | | - let downloadBytes = 0 |
142 | | - |
143 | | - win.webContents.session.once ( 'will-download', ( event, item, webContents ) => { |
144 | | - |
145 | | - item.setSavePath ( saveFilePath ) |
146 | | - //startTime = new Date ().getTime () |
147 | | - console.log ( `start download file from [${ downloadUrl }]\r\n saveTo [${ saveFilePath }]`) |
148 | | - /* |
149 | | - const DEBUG = true |
150 | | - item.on ( 'updated', ( event, state ) => { |
151 | | - if ( state === 'interrupted') { |
152 | | - if ( DEBUG ) |
153 | | - console.log ( 'hideWindowDownload: Download is interrupted but can be resumed' + item.getURL() ) |
154 | | - return |
155 | | - } |
156 | | - |
157 | | - if ( item.isPaused ()) { |
158 | | - if ( DEBUG ) |
159 | | - console.log ( 'hideWindowDownload: Download is interrupted but can be resumed' + item.getURL()) |
160 | | - return |
161 | | - } |
162 | | - downloadBytes = item.getReceivedBytes() |
163 | | - if ( DEBUG ) |
164 | | - console.log ( `${item.getFilename()} Received bytes: ${item.getReceivedBytes()}`) |
165 | | - return |
166 | | - }) |
167 | | - */ |
168 | | - item.once ( 'done', ( event, state ) => { |
169 | | - if ( state === 'completed' ) { |
170 | | - console.log ( `download [${ saveFilePath }] success!`) |
171 | | - |
172 | | - return win.close () |
173 | | - } |
174 | | - |
175 | | - return Fs.unlink ( saveFilePath, err => { |
176 | | - _err = new Error ( state ) |
177 | | - console.log ( `Download failed: ${state}` ) |
178 | | - return win.close () |
179 | | - }) |
180 | | - |
181 | | - }) |
182 | | - }) |
183 | | - win.once ( 'closed', () => { |
184 | | - |
185 | | - win = null |
186 | | - if ( _err ) |
187 | | - return Callback ( _err ) |
188 | | - return Callback () |
189 | | - }) |
190 | | - return win.loadURL ( downloadUrl ) |
191 | | - }) |
192 | | -} |
193 | | - |
194 | 116 | const _doUpdate = ( tag_name: string, _port ) => { |
195 | 117 | let url = null |
196 | 118 |
|
@@ -229,21 +151,6 @@ const _doUpdate = ( tag_name: string, _port ) => { |
229 | 151 | autoUpdater.checkForUpdates () |
230 | 152 | } |
231 | 153 |
|
232 | | -const dirTitleErr = [ |
233 | | - [ |
234 | | - '文件夹创建错误', |
235 | | - 'フォルダ作成エラー', |
236 | | - 'Create folder error', |
237 | | - '文件夾創建錯誤' |
238 | | - ], |
239 | | - [ |
240 | | - 'QTGate在[__folder__]位置创建文件夹错误,QTGate安装不能够继续进行,请检查您的系统。', |
241 | | - 'QTGateは[__folder__]にフォルダを作成エラー、QTGateはインストールができません。あなたのシステムをチェックしてください。', |
242 | | - 'QTGate install got error when make a folder at [__folder__], please check your OS system and do QTGate install again.', |
243 | | - 'QTGate在[__folder__]位置創建文件夾錯誤,QTGate安裝不能夠繼續進行,請檢查您的系統。' |
244 | | - ] |
245 | | -] |
246 | | - |
247 | 154 | const createWindow = () => { |
248 | 155 | shell.openExternal (`http://127.0.0.1:${ port }`) |
249 | 156 |
|
@@ -300,12 +207,6 @@ const data11 = [ |
300 | 207 | } |
301 | 208 | ] |
302 | 209 |
|
303 | | -const showError = ( title: string, detail: string, app ) => { |
304 | | - dialog.showErrorBox ( title, detail) |
305 | | - if ( app ) |
306 | | - return app.quit() |
307 | | -} |
308 | | - |
309 | 210 | const getLocalLanguage = ( lang: string ) => { |
310 | 211 | if ( /^zh-TW|^zh-HK|^zh-SG/i.test ( lang )) |
311 | 212 | return 3 |
|
0 commit comments