Skip to content

Commit

Permalink
Merge pull request #942 from agalwood/hotfix/auto_update_20210511
Browse files Browse the repository at this point in the history
fix: some bug
  • Loading branch information
agalwood authored May 12, 2021
2 parents da2b663 + c257816 commit 85ae4cd
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,9 @@ export default class Application extends EventEmitter {
win.setProgressBar(0)
})

this.updateManager.on('will-updated', (event) => {
this.updateManager.on('will-updated', async (event) => {
this.windowManager.setWillQuit(true)
await this.stop()
})

this.updateManager.on('update-error', (event) => {
Expand Down Expand Up @@ -651,7 +652,7 @@ export default class Application extends EventEmitter {
})

this.on('application:change-theme', (theme) => {
this.themeManager.updateAppAppearance(theme)
this.themeManager.updateSystemTheme(theme)
this.sendCommandToAll('application:update-theme', { theme })
})

Expand Down
21 changes: 16 additions & 5 deletions src/main/core/UpdateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export default class UpdateManager extends EventEmitter {
this.options = options
this.i18n = getI18n()

this.isChecking = false
this.updater = autoUpdater
this.updater.autoDownload = false
this.updater.autoInstallOnAppQuit = false
this.updater.logger = logger
this.autoCheckData = {
checkEnable: this.options.autoCheck,
Expand All @@ -40,9 +42,10 @@ export default class UpdateManager extends EventEmitter {
this.updater.on('update-not-available', this.updateNotAvailable.bind(this))
this.updater.on('download-progress', this.updateDownloadProgress.bind(this))
this.updater.on('update-downloaded', this.updateDownloaded.bind(this))
this.updater.on('update-cancelled', this.updateCancelled.bind(this))
this.updater.on('error', this.updateError.bind(this))

if (this.autoCheckData.checkEnable) {
if (this.autoCheckData.checkEnable && !this.isChecking) {
this.autoCheckData.userCheck = false
this.updater.checkForUpdates()
}
Expand All @@ -54,6 +57,7 @@ export default class UpdateManager extends EventEmitter {
}

checkingForUpdate () {
this.isChecking = true
this.emit('checking')
}

Expand All @@ -73,6 +77,7 @@ export default class UpdateManager extends EventEmitter {
}

updateNotAvailable (event, info) {
this.isChecking = false
this.emit('update-not-available', info)
if (this.autoCheckData.userCheck) {
dialog.showMessageBox({
Expand Down Expand Up @@ -102,20 +107,26 @@ export default class UpdateManager extends EventEmitter {
title: this.i18n.t('app.check-for-updates-title'),
message: this.i18n.t('app.update-downloaded-message')
}).then(_ => {
this.isChecking = false
this.emit('will-updated')
setImmediate(() => {
setTimeout(() => {
this.updater.quitAndInstall()
})
}, 200)
})
}

updateCancelled () {
this.isChecking = false
}

updateError (event, error) {
this.isChecking = false
this.emit('update-error', error)
const msg = (error == null)
? this.i18n.t('update-error-message')
? this.i18n.t('app.update-error-message')
: (error.stack || error).toString()

this.updater.logger.warn(`[Motrix] update-error: ${msg}`)
dialog.showErrorBox(msg)
dialog.showErrorBox('Error', msg)
}
}
17 changes: 6 additions & 11 deletions src/main/ui/ThemeManager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EventEmitter } from 'events'
import { nativeTheme, systemPreferences } from 'electron'
import { nativeTheme } from 'electron'
import is from 'electron-is'

import { APP_THEME } from '@shared/constants'
import logger from '../core/Logger'
import { getSystemTheme } from '../utils'

export default class ThemeManager extends EventEmitter {
Expand Down Expand Up @@ -31,19 +32,13 @@ export default class ThemeManager extends EventEmitter {
nativeTheme.on('updated', () => {
const theme = getSystemTheme()
this.systemTheme = theme
console.log('nativeTheme updated===>', theme)
logger.info('[Motrix] nativeTheme updated===>', theme)
this.emit('system-theme-change', theme)
})
}

/**
* deprecated
* @see https://www.electronjs.org/docs/all#systempreferencessetapplevelappearanceappearance-macos-deprecated
*/
updateAppAppearance (theme) {
if (!is.macOS() || theme !== APP_THEME.LIGHT || theme !== APP_THEME.DARK) {
return
}
systemPreferences.setAppLevelAppearance(theme)
updateSystemTheme (theme) {
theme = theme === APP_THEME.AUTO ? 'system' : theme
nativeTheme.themeSource = theme
}
}
1 change: 1 addition & 0 deletions src/renderer/components/Theme/Default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ body {
BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB",
"Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-variant: tabular-nums;
font-size: $--font-size-medium;
}

::-webkit-scrollbar {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Theme/Variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ $--size-base: 14px !default;
-------------------------- */
$--index-normal: 1 !default;
$--index-top: 1000 !default;
$--index-popper: 2000 !default;
$--index-popper: 2100 !default;

/* Disable base
-------------------------- */
Expand Down
12 changes: 10 additions & 2 deletions src/renderer/store/modules/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ const actions = {
const { gid, options } = payload
return api.changeOption({ gid, options })
},
removeTask ({ dispatch }, task) {
removeTask ({ state, dispatch }, task) {
const { gid } = task
if (gid === state.currentTaskGid) {
dispatch('hideTaskDetail')
}

return api.removeTask({ gid })
.finally(() => {
dispatch('fetchList')
Expand Down Expand Up @@ -231,8 +235,12 @@ const actions = {
}
return dispatch('changeTaskOption', { gid, options })
},
removeTaskRecord ({ dispatch }, task) {
removeTaskRecord ({ state, dispatch }, task) {
const { gid, status } = task
if (gid === state.currentTaskGid) {
dispatch('hideTaskDetail')
}

const { ERROR, COMPLETE, REMOVED } = TASK_STATUS
if ([ERROR, COMPLETE, REMOVED].indexOf(status) === -1) {
return
Expand Down
4 changes: 4 additions & 0 deletions src/shared/utils/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const buildOuts = (uris = [], out = '') => {
return result
}

if (count === 1) {
return [out]
}

const ruleStr = getRuleString(out)
if (!ruleStr) {
return result
Expand Down

0 comments on commit 85ae4cd

Please sign in to comment.