Skip to content

Commit

Permalink
chore: update electron version
Browse files Browse the repository at this point in the history
  • Loading branch information
xVanTuring authored and xVanTuring committed Sep 27, 2019
1 parent a27cb2b commit 341039b
Show file tree
Hide file tree
Showing 4 changed files with 699 additions and 510 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^1.8.2",
"electron-builder": "^19.19.1",
"electron-debug": "^1.4.0",
"electron": "^6.0.10",
"electron-builder": "^21.2.0",
"electron-debug": "^3.0.1",
"electron-devtools-installer": "^2.2.0",
"eslint": "^4.19.1",
"eslint-friendly-formatter": "^3.0.0",
Expand Down
194 changes: 97 additions & 97 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,117 +16,117 @@ import logger from './logger'
import { clearShortcuts } from './shortcut'
import { loadConfigsFromString } from '../shared/ssr'
import { isMac, isWin } from '../shared/env'
const isPrimaryInstance = app.requestSingleInstanceLock()

const isSecondInstance = app.makeSingleInstance((argv, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
const _window = getWindow()
if (_window) {
if (_window.isMinimized()) {
_window.restore()
}
_window.focus()
}
// 如果是通过链接打开的应用,则添加记录
if (argv[1]) {
const configs = loadConfigsFromString(argv[1])
if (configs.length) {
addConfigs(configs)
}
}
})

if (isSecondInstance) {
if (!isPrimaryInstance) {
// cannot find module '../dialog'
// https://github.com/electron/electron/issues/8862#issuecomment-294303518
app.exit()
}

bootstrap.then(() => {
createWindow()
if (isWin || isMac) {
app.setAsDefaultProtocolClient('ssr')
app.setAsDefaultProtocolClient('ss')
}
} else {
app.on('second-instance', (event, argv) => {
const _window = getWindow()
if (_window) {
if (_window.isMinimized()) {
_window.restore()
}
_window.focus()
}
// 如果是通过链接打开的应用,则添加记录
if (argv[1]) {
const configs = loadConfigsFromString(argv[1])
if (configs.length) {
addConfigs(configs)
}
}
})

if (process.env.NODE_ENV !== 'development') {
checkUpdate()
}
bootstrap.then(() => {
createWindow()
if (isWin || isMac) {
app.setAsDefaultProtocolClient('ssr')
app.setAsDefaultProtocolClient('ss')
}

// 开机自启动配置
const AutoLauncher = new AutoLaunch({
name: 'ShadowsocksR Client',
isHidden: true,
mac: {
useLaunchAgent: true
if (process.env.NODE_ENV !== 'development') {
checkUpdate()
}
})

appConfig$.subscribe(data => {
const [appConfig, changed] = data
if (!changed.length) {
// 初始化时没有配置则打开页面,有配置则不显示主页面
if (!appConfig.configs.length || !appConfig.ssrPath) {
showWindow()
// 开机自启动配置
const AutoLauncher = new AutoLaunch({
name: 'ShadowsocksR Client',
isHidden: true,
mac: {
useLaunchAgent: true
}
}
if (!changed.length || changed.indexOf('autoLaunch') > -1) {
// 初始化或者选项变更时
AutoLauncher.isEnabled().then(enabled => {
// 状态不相同时
if (appConfig.autoLaunch !== enabled) {
return AutoLauncher[appConfig.autoLaunch ? 'enable' : 'disable']().catch(() => {
logger.error(`${appConfig.autoLaunch ? '执行' : '取消'}开机自启动失败`)
})
})

appConfig$.subscribe(data => {
const [appConfig, changed] = data
if (!changed.length) {
// 初始化时没有配置则打开页面,有配置则不显示主页面
if (!appConfig.configs.length || !appConfig.ssrPath) {
showWindow()
}
}).catch(() => {
logger.error('获取开机自启状态失败')
})
}
})
}
if (!changed.length || changed.indexOf('autoLaunch') > -1) {
// 初始化或者选项变更时
AutoLauncher.isEnabled().then(enabled => {
// 状态不相同时
if (appConfig.autoLaunch !== enabled) {
return AutoLauncher[appConfig.autoLaunch ? 'enable' : 'disable']().catch(() => {
logger.error(`${appConfig.autoLaunch ? '执行' : '取消'}开机自启动失败`)
})
}
}).catch(() => {
logger.error('获取开机自启状态失败')
})
}
})

// 电源状态检测
powerMonitor.on('suspend', () => {
// 系统挂起时
logger.info('power suspend')
stopTask()
// setProxyToNone()
stopCommand(true)
}).on('resume', () => {
// 恢复
logger.info('power resumed')
runWithConfig(currentConfig)
// startProxy()
startTask(currentConfig)
// 电源状态检测
powerMonitor.on('suspend', () => {
// 系统挂起时
logger.info('power suspend')
stopTask()
// setProxyToNone()
stopCommand(true)
}).on('resume', () => {
// 恢复
logger.info('power resumed')
runWithConfig(currentConfig)
// startProxy()
startTask(currentConfig)
})
})
})

app.on('window-all-closed', () => {
logger.debug('window-all-closed')
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('window-all-closed', () => {
logger.debug('window-all-closed')
if (process.platform !== 'darwin') {
app.quit()
}
})

// 由main进程发起的退出
app.on('before-quit', () => { isQuiting(true) })
// 由main进程发起的退出
app.on('before-quit', () => { isQuiting(true) })

app.on('will-quit', e => {
logger.debug('will-quit')
e.preventDefault()
stopTask()
setProxyToNone()
destroyTray()
destroyWindow()
stopHttpProxyServer()
stopPacServer()
clearShortcuts()
stopCommand(true).then(() => {
app.exit(0)
app.on('will-quit', e => {
logger.debug('will-quit')
e.preventDefault()
stopTask()
setProxyToNone()
destroyTray()
destroyWindow()
stopHttpProxyServer()
stopPacServer()
clearShortcuts()
stopCommand(true).then(() => {
app.exit(0)
})
})
})

app.on('activate', () => {
if (getWindow() === null) {
createWindow()
}
})
app.on('activate', () => {
if (getWindow() === null) {
createWindow()
}
})
}
2 changes: 1 addition & 1 deletion src/main/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function createWindow () {
minimizable: false,
maximizable: false,
show: false,
webPreferences: { webSecurity: process.env.NODE_ENV !== 'development' }
webPreferences: { webSecurity: process.env.NODE_ENV !== 'development', nodeIntegration: true }
})
mainWindow.setMenu(null)
mainWindow.loadURL(winURL)
Expand Down
Loading

0 comments on commit 341039b

Please sign in to comment.