Skip to content

A full-featured download manager.

feat: preference basic show progress bar

Dr_rOota07f81e20cfc
diff --git a/src/main/Application.js b/src/main/Application.js
index 094d64be..27b3ead4 100644
--- a/src/main/Application.js
+++ b/src/main/Application.js
@@ -271,6 +271,20 @@ export default class Application extends EventEmitter {
})
}
+ watchShowProgressBarChange () {
+ const { userConfig } = this.configManager
+ const key = 'show-progress-bar'
+ this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
+ logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
+
+ if (newValue) {
+ this.bindProgressChange()
+ } else {
+ this.unbindProgressChange()
+ }
+ })
+ }
+
initUPnPManager () {
this.upnp = new UPnPManager()
@@ -829,6 +843,7 @@ export default class Application extends EventEmitter {
this.watchOpenAtLoginChange()
this.watchProtocolsChange()
this.watchRunModeChange()
+ this.watchShowProgressBarChange()
this.on('download-status-change', (downloading) => {
this.trayManager.handleDownloadStatusChange(downloading)
@@ -853,15 +868,36 @@ export default class Application extends EventEmitter {
app.addRecentDocument(path)
})
- this.on('progress-change', (progress) => {
- if (this.updateManager.isChecking) {
- return
- }
- if (!is.windows() && progress === 2) {
- progress = 0
- }
- this.windowManager.getWindow('index').setProgressBar(progress)
- })
+ if (this.configManager.userConfig.get('show-progress-bar')) {
+ this.bindProgressChange()
+ }
+ }
+
+ handleProgressChange (progress) {
+ if (this.updateManager.isChecking) {
+ return
+ }
+ if (!is.windows() && progress === 2) {
+ progress = 0
+ }
+ this.windowManager.getWindow('index').setProgressBar(progress)
+ }
+
+ bindProgressChange () {
+ if (this.listeners('progress-change').length > 0) {
+ return
+ }
+
+ this.on('progress-change', this.handleProgressChange)
+ }
+
+ unbindProgressChange () {
+ if (this.listeners('progress-change').length === 0) {
+ return
+ }
+
+ this.off('progress-change', this.handleProgressChange)
+ this.windowManager.getWindow('index').setProgressBar(-1)
}
handleIpcMessages () {
diff --git a/src/main/core/ConfigManager.js b/src/main/core/ConfigManager.js
index 3135dec4..f773322f 100644
--- a/src/main/core/ConfigManager.js
+++ b/src/main/core/ConfigManager.js
@@ -117,6 +117,7 @@ export default class ConfigManager {
'protocols': { 'magnet': true, 'thunder': false },
'resume-all-when-app-launched': false,
'run-mode': APP_RUN_MODE.STANDARD,
+ 'show-progress-bar': true,
'task-notification': true,
'theme': APP_THEME.AUTO,
'tracker-source': [
diff --git a/src/renderer/components/Preference/Basic.vue b/src/renderer/components/Preference/Basic.vue
index 9a6c8188..497ad7b4 100644
--- a/src/renderer/components/Preference/Basic.vue
+++ b/src/renderer/components/Preference/Basic.vue
@@ -43,6 +43,11 @@
{{ $t('preferences.tray-speedometer') }}
</el-checkbox>
</el-col>
+ <el-col class="form-item-sub" :span="16">
+ <el-checkbox v-model="form.showProgressBar">
+ {{ $t('preferences.show-progress-bar') }}
+ </el-checkbox>
+ </el-col>
</el-form-item>
<el-form-item
v-if="isMac"
@@ -339,6 +344,7 @@
runMode,
seedRatio,
seedTime,
+ showProgressBar,
taskNotification,
theme,
traySpeedometer
@@ -368,6 +374,7 @@
runMode,
seedRatio,
seedTime,
+ showProgressBar,
taskNotification,
theme,
traySpeedometer
diff --git a/src/shared/configKeys.js b/src/shared/configKeys.js
index 702e3694..04605cd9 100644
--- a/src/shared/configKeys.js
+++ b/src/shared/configKeys.js
@@ -23,6 +23,7 @@ const userKeys = [
'resume-all-when-app-launched',
'run-mode',
'session-path',
+ 'show-progress-bar',
'task-notification',
'theme',
'tracker-source',