heynote/webapp/bridge.js
Jonatan Heyman 079fa666d6
Implement web version of Heynote (#63)
* 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.
2023-12-25 14:18:44 +01:00

81 lines
2.1 KiB
JavaScript

const mediaMatch = window.matchMedia('(prefers-color-scheme: dark)')
let themeModeChangeListener = null
let autoUpdateCallbacks = null
let themeCallback = null
let currencyData = null
export default {
platform: {
isMac: true,
isWindows: false,
isLinux: false,
},
buffer: {
async load() {
const content = localStorage.getItem("buffer")
return content === null ? "\n∞∞∞text-a\n" : content
},
async save(content) {
console.log("saving buffer")
localStorage.setItem("buffer", content)
},
async saveAndQuit(content) {
},
},
onWindowClose(callback) {
//ipcRenderer.on(WINDOW_CLOSE_EVENT, callback)
},
onOpenSettings(callback) {
//ipcRenderer.on(OPEN_SETTINGS_EVENT, callback)
},
onSettingsChange(callback) {
//ipcRenderer.on(SETTINGS_CHANGE_EVENT, (event, settings) => callback(settings))
},
themeMode: {
set: (mode) => {
themeCallback(mode)
document.body.setAttribute("theme", mode === "dark" ? "dark" : "light")
},
get: async () => {
return {
theme: "light",
computed: "light",
}
},
onChange: (callback) => {
themeCallback = callback
themeModeChangeListener = (event) => {
callback(event.matches ? "dark" : "light")
}
mediaMatch.addEventListener('change', themeModeChangeListener)
return mediaMatch
},
removeListener() {
mediaMatch.removeEventListener('change', themeModeChangeListener)
},
initial: "light",
},
settings: {
keymap: "default",
},
getCurrencyData: async () => {
if (currencyData !== null) {
return currencyData
}
const response = await fetch("https://currencies.heynote.com/rates.json", {cache: "no-cache"})
currencyData = JSON.parse(await response.text())
return currencyData
},
}