2023-12-25 14:18:44 +01:00
|
|
|
const mediaMatch = window.matchMedia('(prefers-color-scheme: dark)')
|
|
|
|
let themeCallback = null
|
2023-12-28 16:48:56 +01:00
|
|
|
mediaMatch.addEventListener("change", async (event) => {
|
|
|
|
if (themeCallback) {
|
|
|
|
themeCallback((await Heynote.themeMode.get()).computed)
|
|
|
|
}
|
|
|
|
})
|
2023-12-25 14:18:44 +01:00
|
|
|
|
2023-12-28 16:48:56 +01:00
|
|
|
let autoUpdateCallbacks = null
|
2023-12-25 14:18:44 +01:00
|
|
|
let currencyData = null
|
|
|
|
|
2023-12-28 18:01:10 +01:00
|
|
|
let platform
|
|
|
|
const uaPlatform = window.navigator?.userAgentData?.platform || window.navigator.platform
|
|
|
|
if (uaPlatform.indexOf("Win") !== -1) {
|
|
|
|
platform = {
|
|
|
|
isMac: false,
|
|
|
|
isWindows: true,
|
|
|
|
isLinux: false,
|
|
|
|
}
|
|
|
|
} else if (uaPlatform.indexOf("Linux") !== -1) {
|
|
|
|
platform = {
|
|
|
|
isMac: false,
|
|
|
|
isWindows: false,
|
|
|
|
isLinux: true,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
platform = {
|
2023-12-25 14:18:44 +01:00
|
|
|
isMac: true,
|
|
|
|
isWindows: false,
|
|
|
|
isLinux: false,
|
2023-12-28 18:01:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Heynote = {
|
|
|
|
platform: platform,
|
2023-12-25 14:18:44 +01:00
|
|
|
|
|
|
|
buffer: {
|
|
|
|
async load() {
|
|
|
|
const content = localStorage.getItem("buffer")
|
|
|
|
return content === null ? "\n∞∞∞text-a\n" : content
|
|
|
|
},
|
|
|
|
|
|
|
|
async save(content) {
|
|
|
|
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) => {
|
2023-12-28 16:48:56 +01:00
|
|
|
localStorage.setItem("theme", mode)
|
2023-12-25 14:18:44 +01:00
|
|
|
themeCallback(mode)
|
2023-12-28 16:48:56 +01:00
|
|
|
console.log("set theme to", mode)
|
2023-12-25 14:18:44 +01:00
|
|
|
},
|
|
|
|
get: async () => {
|
2023-12-28 16:48:56 +01:00
|
|
|
const theme = localStorage.getItem("theme") || "system"
|
|
|
|
const systemTheme = mediaMatch.matches ? "dark" : "light"
|
2023-12-25 14:18:44 +01:00
|
|
|
return {
|
2023-12-28 16:48:56 +01:00
|
|
|
theme: theme,
|
|
|
|
computed: theme === "system" ? systemTheme : theme,
|
2023-12-25 14:18:44 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onChange: (callback) => {
|
|
|
|
themeCallback = callback
|
|
|
|
},
|
|
|
|
removeListener() {
|
2023-12-28 16:48:56 +01:00
|
|
|
themeCallback = null
|
2023-12-25 14:18:44 +01:00
|
|
|
},
|
2023-12-28 16:48:56 +01:00
|
|
|
initial: localStorage.getItem("theme") || "system",
|
2023-12-25 14:18:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
}
|
2023-12-28 16:48:56 +01:00
|
|
|
|
|
|
|
export default Heynote
|