Skip to content

Commit 5ea19eb

Browse files
authored
Merge pull request #1412 from agalwood/feature/hide_tray_20230401
feat: hide tray application
2 parents 55e2a42 + 8857290 commit 5ea19eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1619
-1481
lines changed

CONTRIBUTING-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## 🌍 翻译指南
66

7-
首先你要确定一个语言的英文简写作为 **locale**,如 en-US,这个 locale 值请严格参考 [Electron 的 Locales 文档](https://www.electronjs.org/docs/api/app#appgetlocale)
7+
首先你要确定一个语言的英文简写作为 **locale**,如 en-US,这个 locale 值请严格参考 [Electron 的 Locales 文档](https://www.electronjs.org/docs/api/app#appgetlocale)[Chromium 源代码](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/l10n/l10n_util.cc)
88

99
Motrix 的国际化分两部分:
1010

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Before you start contributing, make sure you already understand [GitHub flow](ht
44

55
## 🌍 Translation Guide
66

7-
First you need to determine the English abbreviation of a language as **locale**, such as en-US, this locale value should strictly refer to the [electron's documentation](https://www.electronjs.org/docs/api/app#appgetlocale).
7+
First you need to determine the English abbreviation of a language as **locale**, such as en-US, this locale value should strictly refer to the [Electron's Documentation](https://www.electronjs.org/docs/api/app#appgetlocale) and [Chromium Source Code](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/l10n/l10n_util.cc).
88

99
The internationalization of Motrix is divided into two parts:
1010

README-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ yarn run build
206206
| ja | 日本語 | ✔️ [@hbkrkzk](https://github.com/hbkrkzk) |
207207
| ko | 한국어 | ✔️ [@KOZ39](https://github.com/KOZ39) |
208208
| nb | Norsk Bokmål | ✔️ [@rubjo](https://github.com/rubjo) |
209+
| nl | Nederlands | ✔️ [@nickbouwhuis](https://github.com/nickbouwhuis) |
209210
| pl | Polski | ✔️ [@KanarekLife](https://github.com/KanarekLife) |
210211
| pt-BR | Portuguese (Brazil) | ✔️ [@andrenoberto](https://github.com/andrenoberto) |
211212
| ro | Română | ✔️ [@alyn3d](https://github.com/alyn3d) |

extra/darwin/arm64/engine/aria2.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ max-file-not-found=5
3838
max-tries=5
3939
# aria2 does not split less than 2*SIZE byte range.
4040
min-split-size=1M
41-
# Set user agent for HTTP(S) downloads.
42-
user-agent=Transmission/3.00
4341
# Send Accept: deflate, gzip request header
4442
http-accept-gzip=true
4543

extra/darwin/x64/engine/aria2.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ max-file-not-found=5
3838
max-tries=5
3939
# aria2 does not split less than 2*SIZE byte range.
4040
min-split-size=1M
41-
# Set user agent for HTTP(S) downloads.
42-
user-agent=Transmission/3.00
4341
# Send Accept: deflate, gzip request header
4442
http-accept-gzip=true
4543

extra/linux/engine/aria2.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ max-file-not-found=5
3838
max-tries=5
3939
# aria2 does not split less than 2*SIZE byte range.
4040
min-split-size=1M
41-
# Set user agent for HTTP(S) downloads.
42-
user-agent=Transmission/3.00
4341
# Send Accept: deflate, gzip request header
4442
http-accept-gzip=true
4543

extra/win32/ia32/engine/aria2.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ max-file-not-found=5
3838
max-tries=5
3939
# aria2 does not split less than 2*SIZE byte range.
4040
min-split-size=1M
41-
# Set user agent for HTTP(S) downloads.
42-
user-agent=Transmission/3.00
4341
# Send Accept: deflate, gzip request header
4442
http-accept-gzip=true
4543

extra/win32/x64/engine/aria2.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ max-file-not-found=5
3838
max-tries=5
3939
# aria2 does not split less than 2*SIZE byte range.
4040
min-split-size=1M
41-
# Set user agent for HTTP(S) downloads.
42-
user-agent=Transmission/3.00
4341
# Send Accept: deflate, gzip request header
4442
http-accept-gzip=true
4543

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Motrix",
3-
"version": "1.7.2",
3+
"version": "1.8.0",
44
"description": "A full-featured download manager",
55
"homepage": "https://motrix.app",
66
"author": {
@@ -58,10 +58,10 @@
5858
"ws": "^8.13.0"
5959
},
6060
"devDependencies": {
61-
"@babel/core": "^7.21.3",
61+
"@babel/core": "^7.21.4",
6262
"@babel/plugin-proposal-class-properties": "^7.18.6",
63-
"@babel/plugin-transform-runtime": "^7.21.0",
64-
"@babel/preset-env": "^7.20.2",
63+
"@babel/plugin-transform-runtime": "^7.21.4",
64+
"@babel/preset-env": "^7.21.4",
6565
"@babel/register": "^7.21.0",
6666
"@electron/notarize": "^1.2.3",
6767
"@electron/osx-sign": "^1.0.4",
@@ -77,7 +77,7 @@
7777
"copy-webpack-plugin": "^11.0.0",
7878
"cross-env": "^7.0.3",
7979
"css-loader": "^6.7.3",
80-
"css-minimizer-webpack-plugin": "^4.2.2",
80+
"css-minimizer-webpack-plugin": "^5.0.0",
8181
"del": "^6.1.1",
8282
"electron": "^22.3.3",
8383
"electron-builder": "^23.6.0",
@@ -102,7 +102,7 @@
102102
"vue-template-compiler": "^2.7.14",
103103
"webpack": "^5.77.0",
104104
"webpack-cli": "^5.0.1",
105-
"webpack-dev-server": "^4.13.1",
105+
"webpack-dev-server": "^4.13.2",
106106
"webpack-hot-middleware": "^2.25.3",
107107
"webpack-merge": "^5.8.0",
108108
"worker-loader": "^3.0.8"

src/main/Application.js

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { app, shell, dialog, ipcMain } from 'electron'
33
import is from 'electron-is'
44
import { readFile, unlink } from 'fs'
55
import { extname, basename } from 'path'
6-
import { isEmpty } from 'lodash'
6+
import { isEmpty, isEqual } from 'lodash'
77

88
import {
99
APP_RUN_MODE,
@@ -42,11 +42,9 @@ export default class Application extends EventEmitter {
4242
}
4343

4444
init () {
45-
this.configManager = this.initConfigManager()
45+
this.initConfigManager()
4646

47-
this.locale = this.configManager.getLocale()
48-
this.localeManager = setupLocaleManager(this.locale)
49-
this.i18n = this.localeManager.getI18n()
47+
this.initLocaleManager()
5048

5149
this.setupApplicationMenu()
5250

@@ -66,9 +64,9 @@ export default class Application extends EventEmitter {
6664

6765
this.initDockManager()
6866

69-
this.autoLaunchManager = new AutoLaunchManager()
67+
this.initAutoLaunchManager()
7068

71-
this.energyManager = new EnergyManager()
69+
this.initEnergyManager()
7270

7371
this.initUpdaterManager()
7472

@@ -87,7 +85,7 @@ export default class Application extends EventEmitter {
8785

8886
initConfigManager () {
8987
this.configListeners = {}
90-
return new ConfigManager()
88+
this.configManager = new ConfigManager()
9189
}
9290

9391
offConfigListeners () {
@@ -101,6 +99,12 @@ export default class Application extends EventEmitter {
10199
this.configListeners = {}
102100
}
103101

102+
initLocaleManager () {
103+
this.locale = this.configManager.getLocale()
104+
this.localeManager = setupLocaleManager(this.locale)
105+
this.i18n = this.localeManager.getI18n()
106+
}
107+
104108
setupApplicationMenu () {
105109
this.menuManager = new MenuManager()
106110
this.menuManager.setup(this.locale)
@@ -162,11 +166,20 @@ export default class Application extends EventEmitter {
162166
})
163167
}
164168

169+
initAutoLaunchManager () {
170+
this.autoLaunchManager = new AutoLaunchManager()
171+
}
172+
173+
initEnergyManager () {
174+
this.energyManager = new EnergyManager()
175+
}
176+
165177
initTrayManager () {
166178
this.trayManager = new TrayManager({
167179
theme: this.configManager.getUserConfig('tray-theme'),
168180
systemTheme: this.themeManager.getSystemTheme(),
169-
speedometer: this.configManager.getUserConfig('tray-speedometer')
181+
speedometer: this.configManager.getUserConfig('tray-speedometer'),
182+
runMode: this.configManager.getUserConfig('run-mode')
170183
})
171184

172185
this.watchTraySpeedometerEnabledChange()
@@ -191,8 +204,8 @@ export default class Application extends EventEmitter {
191204
watchTraySpeedometerEnabledChange () {
192205
const { userConfig } = this.configManager
193206
const key = 'tray-speedometer'
194-
this.configListeners[key] = userConfig.onDidChange('tray-speedometer', async (newValue, oldValue) => {
195-
logger.info('[Motrix] detected tray speedometer value change event:', newValue, oldValue)
207+
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
208+
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
196209
this.trayManager.handleSpeedometerEnableChange(newValue)
197210
})
198211
}
@@ -203,6 +216,55 @@ export default class Application extends EventEmitter {
203216
})
204217
}
205218

219+
watchOpenAtLoginChange () {
220+
const { userConfig } = this.configManager
221+
const key = 'open-at-login'
222+
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
223+
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
224+
if (is.linux()) {
225+
return
226+
}
227+
228+
if (newValue) {
229+
this.autoLaunchManager.enable()
230+
} else {
231+
this.autoLaunchManager.disable()
232+
}
233+
})
234+
}
235+
236+
watchProtocolsChange () {
237+
const { userConfig } = this.configManager
238+
const key = 'protocols'
239+
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
240+
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
241+
242+
if (!newValue || isEqual(newValue, oldValue)) {
243+
return
244+
}
245+
246+
logger.info('[Motrix] setup protocols client:', newValue)
247+
this.protocolManager.setup(newValue)
248+
})
249+
}
250+
251+
watchRunModeChange () {
252+
const { userConfig } = this.configManager
253+
const key = 'run-mode'
254+
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
255+
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
256+
this.trayManager.handleRunModeChange(newValue)
257+
258+
if (newValue !== APP_RUN_MODE.TRAY) {
259+
this.dockManager.show()
260+
} else {
261+
this.dockManager.hide()
262+
// Hiding the dock icon will trigger the entire app to hide.
263+
this.show()
264+
}
265+
})
266+
}
267+
206268
initUPnPManager () {
207269
this.upnp = new UPnPManager()
208270

@@ -365,7 +427,7 @@ export default class Application extends EventEmitter {
365427

366428
this.windowManager.on('leave-full-screen', (window) => {
367429
const mode = this.configManager.getUserConfig('run-mode')
368-
if (mode !== APP_RUN_MODE.STANDARD) {
430+
if (mode === APP_RUN_MODE.TRAY) {
369431
this.dockManager.hide()
370432
}
371433
})
@@ -393,6 +455,7 @@ export default class Application extends EventEmitter {
393455
this.isReady = true
394456
this.emit('ready')
395457
})
458+
396459
if (is.macOS()) {
397460
this.touchBarManager.setup(page, win)
398461
}
@@ -621,18 +684,6 @@ export default class Application extends EventEmitter {
621684
this.quit()
622685
})
623686

624-
this.on('application:open-at-login', (openAtLogin) => {
625-
if (is.linux()) {
626-
return
627-
}
628-
629-
if (openAtLogin) {
630-
this.autoLaunchManager.enable()
631-
} else {
632-
this.autoLaunchManager.disable()
633-
}
634-
})
635-
636687
this.on('application:show', ({ page }) => {
637688
this.show(page)
638689
})
@@ -769,6 +820,10 @@ export default class Application extends EventEmitter {
769820
this.configManager.userConfig.onDidAnyChange(() => this.handleConfigChange('user'))
770821
this.configManager.systemConfig.onDidAnyChange(() => this.handleConfigChange('system'))
771822

823+
this.watchOpenAtLoginChange()
824+
this.watchProtocolsChange()
825+
this.watchRunModeChange()
826+
772827
this.on('download-status-change', (downloading) => {
773828
this.trayManager.handleDownloadStatusChange(downloading)
774829
if (downloading) {

0 commit comments

Comments
 (0)