-
-
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.
- Loading branch information
Showing
20 changed files
with
224 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IpcRenderer } from 'electron'; | ||
|
||
declare global { | ||
interface Window { | ||
ipcRenderer: IpcRenderer; | ||
} | ||
} |
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,20 @@ | ||
import { ipcRenderer } from 'electron'; | ||
import { getUserPreferedTheme, getOsTheme } from '@utils/getThemes'; | ||
import { AppTheme } from '@types'; | ||
|
||
const setInitialAppTheme = async () => { | ||
const userPreference = await getUserPreferedTheme(); | ||
const osTheme = getOsTheme(); | ||
const themeToUse: AppTheme = userPreference && userPreference !== 'system' | ||
? userPreference | ||
: osTheme; | ||
window.document.documentElement.setAttribute('data-theme', themeToUse); | ||
}; | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
setInitialAppTheme(); | ||
}); | ||
|
||
// nodeIntegration is set to `false` for security reasons | ||
// Inject functions needed for web contents here | ||
window.ipcRenderer = ipcRenderer; |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import { | ||
css | ||
} from 'lit-element'; | ||
import { css } from 'lit-element'; | ||
|
||
/** | ||
* Shared styles for buttons. | ||
|
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { AppTheme } from '@types'; | ||
import '@webcomponents/webcomponentsjs/webcomponents-bundle'; | ||
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter'; | ||
|
||
import '@styles/index.scss'; | ||
import './app'; | ||
|
||
// Event Handlers for handiing events sent from main process | ||
window.ipcRenderer.on('CHANGE_RENDERER_THEME', (_, theme: AppTheme) => { | ||
window.document.documentElement.setAttribute('data-theme', 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
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export type Position = { | ||
x?: number; y?: number; | ||
} | ||
|
||
export type AppTheme = 'light' | 'dark'; | ||
export type AppThemeOptions = AppTheme | 'system'; | ||
export type AppThemeStorage = { | ||
theme?: AppThemeOptions; | ||
} |
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,31 @@ | ||
import { nativeTheme } from 'electron'; | ||
import { AppTheme, AppThemeOptions } from '@types'; | ||
import { saveAppTheme } from '@storage'; | ||
import { getOsTheme, getUserPreferedTheme } from './getThemes'; | ||
import getMainWindow from '../main'; | ||
|
||
/** | ||
* Set app theme when user explicitly set it through theme preference menu | ||
*/ | ||
export const setAppTheme = (theme: AppThemeOptions): void => { | ||
const window = getMainWindow(); | ||
const osTheme = getOsTheme(); | ||
const themeToUse: AppTheme = theme !== 'system' ? theme : osTheme; | ||
window.webContents.send('CHANGE_RENDERER_THEME', themeToUse); | ||
saveAppTheme(theme); | ||
}; | ||
|
||
/** | ||
* Listen to theme change on system preferences | ||
*/ | ||
export const listenToSystemThemeChange = (): void => { | ||
nativeTheme.on('updated', async () => { | ||
const window = getMainWindow(); | ||
const userPreference = await getUserPreferedTheme(); | ||
const osTheme = getOsTheme(); | ||
const themeToUse: AppTheme = userPreference && userPreference !== 'system' | ||
? userPreference | ||
: osTheme; | ||
window.webContents.send('CHANGE_RENDERER_THEME', themeToUse); | ||
}); | ||
}; |
Oops, something went wrong.