Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide tray application #1412

Merged
merged 7 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## 🌍 翻译指南

首先你要确定一个语言的英文简写作为 **locale**,如 en-US,这个 locale 值请严格参考 [Electron 的 Locales 文档](https://www.electronjs.org/docs/api/app#appgetlocale)
首先你要确定一个语言的英文简写作为 **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)。

Motrix 的国际化分两部分:

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Before you start contributing, make sure you already understand [GitHub flow](ht

## 🌍 Translation Guide

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).
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).

The internationalization of Motrix is divided into two parts:

Expand Down
1 change: 1 addition & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ yarn run build
| ja | 日本語 | ✔️ [@hbkrkzk](https://github.com/hbkrkzk) |
| ko | 한국어 | ✔️ [@KOZ39](https://github.com/KOZ39) |
| nb | Norsk Bokmål | ✔️ [@rubjo](https://github.com/rubjo) |
| nl | Nederlands | ✔️ [@nickbouwhuis](https://github.com/nickbouwhuis) |
| pl | Polski | ✔️ [@KanarekLife](https://github.com/KanarekLife) |
| pt-BR | Portuguese (Brazil) | ✔️ [@andrenoberto](https://github.com/andrenoberto) |
| ro | Română | ✔️ [@alyn3d](https://github.com/alyn3d) |
Expand Down
2 changes: 0 additions & 2 deletions extra/darwin/arm64/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ max-file-not-found=5
max-tries=5
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Set user agent for HTTP(S) downloads.
user-agent=Transmission/3.00
# Send Accept: deflate, gzip request header
http-accept-gzip=true

Expand Down
2 changes: 0 additions & 2 deletions extra/darwin/x64/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ max-file-not-found=5
max-tries=5
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Set user agent for HTTP(S) downloads.
user-agent=Transmission/3.00
# Send Accept: deflate, gzip request header
http-accept-gzip=true

Expand Down
2 changes: 0 additions & 2 deletions extra/linux/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ max-file-not-found=5
max-tries=5
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Set user agent for HTTP(S) downloads.
user-agent=Transmission/3.00
# Send Accept: deflate, gzip request header
http-accept-gzip=true

Expand Down
2 changes: 0 additions & 2 deletions extra/win32/ia32/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ max-file-not-found=5
max-tries=5
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Set user agent for HTTP(S) downloads.
user-agent=Transmission/3.00
# Send Accept: deflate, gzip request header
http-accept-gzip=true

Expand Down
2 changes: 0 additions & 2 deletions extra/win32/x64/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ max-file-not-found=5
max-tries=5
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Set user agent for HTTP(S) downloads.
user-agent=Transmission/3.00
# Send Accept: deflate, gzip request header
http-accept-gzip=true

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Motrix",
"version": "1.7.2",
"version": "1.8.0",
"description": "A full-featured download manager",
"homepage": "https://motrix.app",
"author": {
Expand Down Expand Up @@ -58,10 +58,10 @@
"ws": "^8.13.0"
},
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/core": "^7.21.4",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.4",
"@babel/register": "^7.21.0",
"@electron/notarize": "^1.2.3",
"@electron/osx-sign": "^1.0.4",
Expand All @@ -77,7 +77,7 @@
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"css-loader": "^6.7.3",
"css-minimizer-webpack-plugin": "^4.2.2",
"css-minimizer-webpack-plugin": "^5.0.0",
"del": "^6.1.1",
"electron": "^22.3.3",
"electron-builder": "^23.6.0",
Expand All @@ -102,7 +102,7 @@
"vue-template-compiler": "^2.7.14",
"webpack": "^5.77.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.1",
"webpack-dev-server": "^4.13.2",
"webpack-hot-middleware": "^2.25.3",
"webpack-merge": "^5.8.0",
"worker-loader": "^3.0.8"
Expand Down
103 changes: 79 additions & 24 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { app, shell, dialog, ipcMain } from 'electron'
import is from 'electron-is'
import { readFile, unlink } from 'fs'
import { extname, basename } from 'path'
import { isEmpty } from 'lodash'
import { isEmpty, isEqual } from 'lodash'

import {
APP_RUN_MODE,
Expand Down Expand Up @@ -42,11 +42,9 @@ export default class Application extends EventEmitter {
}

init () {
this.configManager = this.initConfigManager()
this.initConfigManager()

this.locale = this.configManager.getLocale()
this.localeManager = setupLocaleManager(this.locale)
this.i18n = this.localeManager.getI18n()
this.initLocaleManager()

this.setupApplicationMenu()

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

this.initDockManager()

this.autoLaunchManager = new AutoLaunchManager()
this.initAutoLaunchManager()

this.energyManager = new EnergyManager()
this.initEnergyManager()

this.initUpdaterManager()

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

initConfigManager () {
this.configListeners = {}
return new ConfigManager()
this.configManager = new ConfigManager()
}

offConfigListeners () {
Expand All @@ -101,6 +99,12 @@ export default class Application extends EventEmitter {
this.configListeners = {}
}

initLocaleManager () {
this.locale = this.configManager.getLocale()
this.localeManager = setupLocaleManager(this.locale)
this.i18n = this.localeManager.getI18n()
}

setupApplicationMenu () {
this.menuManager = new MenuManager()
this.menuManager.setup(this.locale)
Expand Down Expand Up @@ -162,11 +166,20 @@ export default class Application extends EventEmitter {
})
}

initAutoLaunchManager () {
this.autoLaunchManager = new AutoLaunchManager()
}

initEnergyManager () {
this.energyManager = new EnergyManager()
}

initTrayManager () {
this.trayManager = new TrayManager({
theme: this.configManager.getUserConfig('tray-theme'),
systemTheme: this.themeManager.getSystemTheme(),
speedometer: this.configManager.getUserConfig('tray-speedometer')
speedometer: this.configManager.getUserConfig('tray-speedometer'),
runMode: this.configManager.getUserConfig('run-mode')
})

this.watchTraySpeedometerEnabledChange()
Expand All @@ -191,8 +204,8 @@ export default class Application extends EventEmitter {
watchTraySpeedometerEnabledChange () {
const { userConfig } = this.configManager
const key = 'tray-speedometer'
this.configListeners[key] = userConfig.onDidChange('tray-speedometer', async (newValue, oldValue) => {
logger.info('[Motrix] detected tray speedometer value change event:', newValue, oldValue)
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
this.trayManager.handleSpeedometerEnableChange(newValue)
})
}
Expand All @@ -203,6 +216,55 @@ export default class Application extends EventEmitter {
})
}

watchOpenAtLoginChange () {
const { userConfig } = this.configManager
const key = 'open-at-login'
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
if (is.linux()) {
return
}

if (newValue) {
this.autoLaunchManager.enable()
} else {
this.autoLaunchManager.disable()
}
})
}

watchProtocolsChange () {
const { userConfig } = this.configManager
const key = 'protocols'
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)

if (!newValue || isEqual(newValue, oldValue)) {
return
}

logger.info('[Motrix] setup protocols client:', newValue)
this.protocolManager.setup(newValue)
})
}

watchRunModeChange () {
const { userConfig } = this.configManager
const key = 'run-mode'
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
logger.info(`[Motrix] detected ${key} value change event:`, newValue, oldValue)
this.trayManager.handleRunModeChange(newValue)

if (newValue !== APP_RUN_MODE.TRAY) {
this.dockManager.show()
} else {
this.dockManager.hide()
// Hiding the dock icon will trigger the entire app to hide.
this.show()
}
})
}

initUPnPManager () {
this.upnp = new UPnPManager()

Expand Down Expand Up @@ -365,7 +427,7 @@ export default class Application extends EventEmitter {

this.windowManager.on('leave-full-screen', (window) => {
const mode = this.configManager.getUserConfig('run-mode')
if (mode !== APP_RUN_MODE.STANDARD) {
if (mode === APP_RUN_MODE.TRAY) {
this.dockManager.hide()
}
})
Expand Down Expand Up @@ -393,6 +455,7 @@ export default class Application extends EventEmitter {
this.isReady = true
this.emit('ready')
})

if (is.macOS()) {
this.touchBarManager.setup(page, win)
}
Expand Down Expand Up @@ -621,18 +684,6 @@ export default class Application extends EventEmitter {
this.quit()
})

this.on('application:open-at-login', (openAtLogin) => {
if (is.linux()) {
return
}

if (openAtLogin) {
this.autoLaunchManager.enable()
} else {
this.autoLaunchManager.disable()
}
})

this.on('application:show', ({ page }) => {
this.show(page)
})
Expand Down Expand Up @@ -769,6 +820,10 @@ export default class Application extends EventEmitter {
this.configManager.userConfig.onDidAnyChange(() => this.handleConfigChange('user'))
this.configManager.systemConfig.onDidAnyChange(() => this.handleConfigChange('system'))

this.watchOpenAtLoginChange()
this.watchProtocolsChange()
this.watchRunModeChange()

this.on('download-status-change', (downloading) => {
this.trayManager.handleDownloadStatusChange(downloading)
if (downloading) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/core/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
NGOSANG_TRACKERS_BEST_IP_URL_CDN,
NGOSANG_TRACKERS_BEST_URL_CDN
} from '@shared/constants'
import { CHROME_UA } from '@shared/ua'
import { separateConfig } from '@shared/utils'
import { reduceTrackerString } from '@shared/utils/tracker'

Expand Down Expand Up @@ -77,7 +78,7 @@ export default class ConfigManager {
'seed-ratio': 1,
'seed-time': 60,
'split': getMaxConnectionPerServer(),
'user-agent': 'Transmission/3.00'
'user-agent': CHROME_UA
}
/* eslint-enable quote-props */
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/ui/DockManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class DockManager extends EventEmitter {
super()
this.options = options
const { runMode } = this.options
if (runMode !== APP_RUN_MODE.STANDARD) {
if (runMode === APP_RUN_MODE.TRAY) {
this.hide()
}
}
Expand Down
Loading