mirror of
https://github.com/heyman/heynote.git
synced 2024-11-22 16:03:28 +01:00
079fa666d6
* Move windows.darkMode -> window.heynote.themeMode * Only add UpdateStatusItem if window.heynote.autoUpdate is set * Update Vite * Implement web version of Heynote. Add a child vite project in ./webapp/ that is Heynote running within a browser. Imports almost all code from ../src/ and only adds a thin bridge that corresponds to the API between the Electron main process and the app code. * Remove commented out tag * Specify publicDir in vite config, instead of using a symlink * Add webapp_dev npm command to package.json * Add npm run command: webapp:build * Add resolve alias '@' that points to project root. Move assets file from public to assets in order to let Vite/Rollup handle bundling.
28 lines
909 B
TypeScript
28 lines
909 B
TypeScript
const { ipcRenderer } = require('electron')
|
|
|
|
const getComputedTheme = () => window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light"
|
|
const mediaMatch = window.matchMedia('(prefers-color-scheme: dark)')
|
|
let themeModeChangeListener = null
|
|
|
|
export default {
|
|
set: (mode) => ipcRenderer.invoke('dark-mode:set', mode),
|
|
get: async () => {
|
|
const mode = await ipcRenderer.invoke('dark-mode:get')
|
|
return {
|
|
theme: mode,
|
|
computed: getComputedTheme(),
|
|
}
|
|
},
|
|
onChange: (callback) => {
|
|
themeModeChangeListener = (event) => {
|
|
callback(event.matches ? "dark" : "light")
|
|
}
|
|
mediaMatch.addEventListener('change', themeModeChangeListener)
|
|
return mediaMatch
|
|
},
|
|
removeListener() {
|
|
mediaMatch.removeEventListener('change', themeModeChangeListener)
|
|
},
|
|
initial: getComputedTheme(),
|
|
}
|