forked from agalwood/Motrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/dark_mode_201904201437'
- Loading branch information
Showing
64 changed files
with
1,005 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.