Skip to content

Commit

Permalink
Merge branch 'feature/dark_mode_201904201437'
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed Apr 23, 2019
2 parents d0085b2 + 6cb278f commit a3bb1c7
Show file tree
Hide file tree
Showing 64 changed files with 1,005 additions and 349 deletions.
2 changes: 1 addition & 1 deletion extra/darwin/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ bt-save-metadata=true

# bt-tracker数据来自https://github.com/ngosang/trackerslist/blob/master/trackers_best.txt

bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.opentrackr.org:1337/announce,udp://tracker.internetwarriors.net:1337/announce,udp://9.rarbg.to:2710/announce,udp://exodus.desync.com:6969/announce,udp://tracker2.itzmx.com:6961/announce,udp://tracker1.itzmx.com:8080/announce,udp://explodie.org:6969/announce,http://tracker.tfile.me:80/announce.php,http://tracker.tfile.me:80/announce,http://tracker.tfile.co:80/announce,http://peersteers.org:80/announce,udp://tracker.tiny-vps.com:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://tracker.port443.xyz:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://thetracker.org:80/announce,udp://retracker.lanta-net.ru:2710/announce
bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.open-internet.nl:6969/announce,udp://tracker.leechers-paradise.org:6969/announce,udp://exodus.desync.com:6969/announce,http://tracker.internetwarriors.net:1337/announce,udp://9.rarbg.to:2710/announce,udp://9.rarbg.me:2710/announce,udp://tracker.opentrackr.org:1337/announce,http://tracker1.itzmx.com:8080/announce,udp://open.demonii.si:1337/announce,udp://tracker.tiny-vps.com:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://bt.xxx-tracker.com:2710/announce,udp://thetracker.org:80/announce,udp://open.stealth.si:80/announce,udp://tracker.port443.xyz:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://explodie.org:6969/announce
2 changes: 1 addition & 1 deletion extra/linux/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ bt-save-metadata=true

# bt-tracker数据来自https://github.com/ngosang/trackerslist/blob/master/trackers_best.txt

bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.opentrackr.org:1337/announce,udp://tracker.internetwarriors.net:1337/announce,udp://9.rarbg.to:2710/announce,udp://exodus.desync.com:6969/announce,udp://tracker2.itzmx.com:6961/announce,udp://tracker1.itzmx.com:8080/announce,udp://explodie.org:6969/announce,http://tracker.tfile.me:80/announce.php,http://tracker.tfile.me:80/announce,http://tracker.tfile.co:80/announce,http://peersteers.org:80/announce,udp://tracker.tiny-vps.com:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://tracker.port443.xyz:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://thetracker.org:80/announce,udp://retracker.lanta-net.ru:2710/announce
bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.open-internet.nl:6969/announce,udp://tracker.leechers-paradise.org:6969/announce,udp://exodus.desync.com:6969/announce,http://tracker.internetwarriors.net:1337/announce,udp://9.rarbg.to:2710/announce,udp://9.rarbg.me:2710/announce,udp://tracker.opentrackr.org:1337/announce,http://tracker1.itzmx.com:8080/announce,udp://open.demonii.si:1337/announce,udp://tracker.tiny-vps.com:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://bt.xxx-tracker.com:2710/announce,udp://thetracker.org:80/announce,udp://open.stealth.si:80/announce,udp://tracker.port443.xyz:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://explodie.org:6969/announce
2 changes: 1 addition & 1 deletion extra/win32/engine/aria2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ bt-save-metadata=true

# bt-tracker数据来自https://github.com/ngosang/trackerslist/blob/master/trackers_best.txt

bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.opentrackr.org:1337/announce,udp://tracker.internetwarriors.net:1337/announce,udp://9.rarbg.to:2710/announce,udp://exodus.desync.com:6969/announce,udp://tracker2.itzmx.com:6961/announce,udp://tracker1.itzmx.com:8080/announce,udp://explodie.org:6969/announce,http://tracker.tfile.me:80/announce.php,http://tracker.tfile.me:80/announce,http://tracker.tfile.co:80/announce,http://peersteers.org:80/announce,udp://tracker.tiny-vps.com:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://tracker.port443.xyz:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://thetracker.org:80/announce,udp://retracker.lanta-net.ru:2710/announce
bt-tracker=udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.open-internet.nl:6969/announce,udp://tracker.leechers-paradise.org:6969/announce,udp://exodus.desync.com:6969/announce,http://tracker.internetwarriors.net:1337/announce,udp://9.rarbg.to:2710/announce,udp://9.rarbg.me:2710/announce,udp://tracker.opentrackr.org:1337/announce,http://tracker1.itzmx.com:8080/announce,udp://open.demonii.si:1337/announce,udp://tracker.tiny-vps.com:6969/announce,udp://tracker.torrent.eu.org:451/announce,udp://denis.stalker.upeer.me:6969/announce,udp://tracker.cyberia.is:6969/announce,udp://bt.xxx-tracker.com:2710/announce,udp://thetracker.org:80/announce,udp://open.stealth.si:80/announce,udp://tracker.port443.xyz:6969/announce,udp://ipv4.tracker.harry.lu:80/announce,udp://explodie.org:6969/announce
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@
"clipboard-polyfill": "^2.7.0",
"electron-debug": "^2.1.0",
"electron-is": "^3.0.0",
"electron-log": "^2.2.17",
"electron-updater": "^4.0.8",
"element-ui": "^2.6.2",
"electron-log": "^3.0.5",
"forever-monitor": "^1.7.1",
"i18next": "^15.0.6",
"lodash": "^4.17.11",
Expand Down Expand Up @@ -205,8 +205,8 @@
"electron-devtools-installer": "^2.2.4",
"electron-notarize": "^0.0.5",
"electron-osx-sign": "^0.4.11",
"electron-store": "^2.0.0",
"eslint": "^5.15.3",
"electron-store": "^3.2.0",
"eslint-config-standard": "^12.0.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.2",
Expand Down
38 changes: 32 additions & 6 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import WindowManager from './ui/WindowManager'
import MenuManager from './ui/MenuManager'
import TouchBarManager from './ui/TouchBarManager'
import TrayManager from './ui/TrayManager'
import ThemeManager from './ui/ThemeManager'

export default class Application extends EventEmitter {
constructor () {
Expand All @@ -30,6 +31,11 @@ export default class Application extends EventEmitter {
this.localeManager = setupLocaleManager(this.locale)
this.i18n = this.localeManager.getI18n()

this.menuManager = new MenuManager()
this.menuManager.setup(this.locale)

this.initTouchBarManager()

this.windowManager = new WindowManager({
userConfig: this.configManager.getUserConfig()
})
Expand All @@ -40,13 +46,10 @@ export default class Application extends EventEmitter {
})
this.startEngine()

this.menuManager = new MenuManager()
this.menuManager.setup(this.locale)

this.touchBarManager = new TouchBarManager()

this.trayManager = new TrayManager()

this.initThemeManager()

this.energyManager = new EnergyManager()

this.initUpdaterManager()
Expand Down Expand Up @@ -84,7 +87,9 @@ export default class Application extends EventEmitter {
this.isReady = true
this.emit('ready')
})
this.touchBarManager.setup(page, win)
if (is.macOS()) {
this.touchBarManager.setup(page, win)
}
}

show (page = 'index') {
Expand All @@ -110,6 +115,7 @@ export default class Application extends EventEmitter {
stop () {
this.engine.stop()
this.energyManager.stopPowerSaveBlocker()
this.trayManager.destroy()
}

sendCommand (command, ...args) {
Expand All @@ -135,6 +141,21 @@ export default class Application extends EventEmitter {
})
}

initThemeManager () {
this.themeManager = new ThemeManager()
this.themeManager.on('system-theme-changed', (theme) => {
this.trayManager.changeIconTheme(theme)
this.sendCommandToAll('application:system-theme', theme)
})
}

initTouchBarManager () {
if (!is.macOS()) {
return
}
this.touchBarManager = new TouchBarManager()
}

initProtocolManager () {
if (is.dev() || is.mas()) {
return
Expand Down Expand Up @@ -257,6 +278,11 @@ export default class Application extends EventEmitter {
this.updateManager.check()
})

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

this.on('application:change-locale', (locale) => {
logger.info('[Motrix] application:change-locale===>', locale)
this.localeManager.changeLanguageByLocale(locale)
Expand Down
51 changes: 28 additions & 23 deletions src/main/core/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@ export default class ConfigManager {
this.systemConfig = new Store({
name: 'system',
defaults: {
dir: getUserDownloadsPath(),
// 断点续传
continue: true,
pause: true,
split: 16,
'rpc-listen-port': 16800,
'rpc-secret': '',
'auto-file-renaming': true,
'all-proxy': '',
'allow-overwrite': true,
'auto-file-renaming': true,
'continue': true,
'dir': getUserDownloadsPath(),
'max-concurrent-downloads': 5,
// macOS 版本修改过源码自己编译的,Linux 和 Windows 版本 暂未处理
'max-connection-per-server': is.macOS() ? 64 : 16,
'min-split-size': '1M',
'max-overall-download-limit': 0,
'max-overall-upload-limit': 0,
'max-download-limit': 0,
'all-proxy': '',
'max-overall-download-limit': 0,
'max-overall-upload-limit': '128K',
'min-split-size': '1M',
'pause': true,
'rpc-listen-port': 16800,
'rpc-secret': '',
'split': 16,
'user-agent': 'Transmission/2.94'
}
})
Expand All @@ -53,20 +51,27 @@ export default class ConfigManager {
initUserConfig () {
this.userConfig = new Store({
name: 'user',
schema: {
theme: {
type: 'string',
enum: ['auto', 'light', 'dark']
}
},
defaults: {
'resume-all-when-app-launched': false,
'task-notification': true,
'hide-app-menu': is.windows() || is.linux(),
'new-task-show-downloading': true,
'auto-check-for-updates': false,
'update-channel': 'latest',
'use-proxy': false,
'all-proxy-backup': '',
'auto-check-for-updates': false,
'auto-check-update': false,
'hide-app-menu': is.windows() || is.linux(),
'last-check-update-time': 0,
'locale': app.getLocale(),
'log-path': getLogPath(),
'new-task-show-downloading': true,
'resume-all-when-app-launched': false,
'session-path': getSessionPath(),
'locale': app.getLocale(),
'auto-check-update': false,
'last-check-update-time': 0
'task-notification': true,
'theme': 'auto',
'update-channel': 'latest',
'use-proxy': false
}
})
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export default class Engine {
// })
}

isRunning (pid) {
try {
return process.kill(pid, 0)
} catch (e) {
return e.code === 'EPERM'
}
}

stop () {
const { pid } = this.instance.child
try {
Expand All @@ -116,7 +124,7 @@ export default class Engine {

forceStop (pid) {
try {
if (pid) {
if (pid && this.isRunning(pid)) {
process.kill(pid)
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/Logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import is from 'electron-is'
import logger from 'electron-log'

logger.transports.file.level = is.production() ? 'warn' : 'info'
logger.transports.file.level = is.production() ? 'warn' : 'silly'
logger.info('Logger init')
logger.warn('[Motrix] Logger init')

Expand Down
46 changes: 46 additions & 0 deletions src/main/ui/ThemeManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { EventEmitter } from 'events'
import { systemPreferences } from 'electron'
import is from 'electron-is'
import { LIGHT_THEME, DARK_THEME } from '@shared/constants'

export default class ThemeManager extends EventEmitter {
constructor (options = {}) {
super()

this.init()
}

init () {
this.handleEvents()
}

getSystemTheme () {
let result = LIGHT_THEME
if (!is.macOS()) {
return result
}
result = systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME
return result
}

handleEvents () {
if (!is.macOS()) {
return
}
systemPreferences.subscribeNotification(
'AppleInterfaceThemeChangedNotification',
() => {
const theme = this.getSystemTheme()
this.updateAppAppearance(theme)
this.emit('system-theme-changed', theme)
}
)
}

updateAppAppearance (theme) {
if (!is.macOS() || theme !== LIGHT_THEME || theme !== DARK_THEME) {
return
}
systemPreferences.setAppLevelAppearance(theme)
}
}
30 changes: 26 additions & 4 deletions src/main/ui/TrayManager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EventEmitter } from 'events'
import { join } from 'path'
import { Tray, Menu } from 'electron'
import { Tray, Menu, systemPreferences } from 'electron'
import is from 'electron-is'
import { translateTemplate } from '../utils/menu'
import { getI18n } from '@/ui/Locale'
import { LIGHT_THEME, DARK_THEME } from '@shared/constants'

let tray = null

Expand All @@ -23,10 +24,11 @@ export default class TrayManager extends EventEmitter {

load () {
this.template = require(`../menus/tray.json`)
const theme = systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME

if (is.macOS()) {
this.normalIcon = join(__static, './mo-tray-normal.png')
this.activeIcon = join(__static, './mo-tray-active.png')
this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
this.activeIcon = join(__static, `./mo-tray-${theme}-active.png`)
} else {
this.normalIcon = join(__static, './mo-tray-colorful-normal.png')
this.activeIcon = join(__static, './mo-tray-colorful-active.png')
Expand Down Expand Up @@ -91,7 +93,27 @@ export default class TrayManager extends EventEmitter {
}

updateStatus (status) {
const icon = status ? this.activeIcon : this.normalIcon
this.status = status
this.updateIcon()
}

updateIcon () {
const icon = this.status ? this.activeIcon : this.normalIcon
tray.setImage(icon)
}

changeIconTheme (theme = LIGHT_THEME) {
if (!is.macOS()) {
return
}

this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
this.activeIcon = join(__static, `./mo-tray-${theme}-active.png`)

this.updateIcon()
}

destroy () {
tray.destroy()
}
}
Binary file added src/renderer/assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/renderer/assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/renderer/assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/renderer/components/About/AppInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
<style lang="scss">
.app-info {
position: relative;
padding: 8px 0;
margin: 8px 0;
.app-version span {
display: inline-block;
vertical-align: bottom;
font-size: $--font-size-large;
margin-left: 20px;
color: $--color-text-regular;
color: $--app-version-color;
line-height: 18px;
}
.app-icon {
Expand All @@ -72,11 +72,11 @@
h4 {
font-size: $--font-size-base;
font-weight: $--font-weight-secondary;
color: $--color-text-regular;
color: $--app-engine-title-color;
}
ul {
font-size: 12px;
color: $--color-text-secondary;
color: $--app-engine-info-color;
list-style: none;
padding: 0;
line-height: 20px;
Expand Down
5 changes: 1 addition & 4 deletions src/renderer/components/About/Copyright.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@
width: 100%;
font-size: $--font-size-small;
a {
color: $--color-text-regular;
color: $--app-copyright-color;
text-decoration: none;
}
}
.copyright-left {
text-align: left;
a {
color: $--color-text-regular;
}
}
.copyright-right {
Expand Down
Loading

0 comments on commit a3bb1c7

Please sign in to comment.