|
1 | 1 | let saveTimeout; |
2 | 2 |
|
3 | | -const version = "1.1.2"; |
| 3 | +const version = "1.1.3"; |
4 | 4 | const electronVersion = "33.2.1"; |
5 | 5 |
|
| 6 | +const defaultThemes = { |
| 7 | + mocha: { |
| 8 | + '--color-bg-dark': '#1e1e2e', |
| 9 | + '--color-bg-darker': '#11111b', |
| 10 | + '--color-bg-medium': '#313244', |
| 11 | + '--color-bg-light': '#45475a', |
| 12 | + '--color-border': '#6c7086', |
| 13 | + '--color-text': '#cdd6f4', |
| 14 | + '--color-placeholder': '#a6adc8', |
| 15 | + '--color-hover': '#585b70', |
| 16 | + '--color-hover-light': '#6c7086', |
| 17 | + '--color-close-hover': '#f38ba8', |
| 18 | + '--color-scrollbar-bg': '#2e3440', |
| 19 | + '--color-scrollbar-thumb': '#4c566a', |
| 20 | + '--color-scrollbar-thumb-hover': '#5e81ac', |
| 21 | + '--color-button-download': '#b4befe', |
| 22 | + '--color-button-download-hover': '#e3e7ff', |
| 23 | + '--color-button-download-text': '#11111b' |
| 24 | + }, |
| 25 | + macchiato: { |
| 26 | + '--color-bg-dark': '#24273a', |
| 27 | + '--color-bg-darker': '#181926', |
| 28 | + '--color-bg-medium': '#1e2030', |
| 29 | + '--color-bg-light': '#363a4f', |
| 30 | + '--color-border': '#494d64', |
| 31 | + '--color-text': '#cad3f5', |
| 32 | + '--color-placeholder': '#a5adcb', |
| 33 | + '--color-hover': '#363a4f', |
| 34 | + '--color-hover-light': '#494d64', |
| 35 | + '--color-close-hover': '#ed8796', |
| 36 | + '--color-scrollbar-bg': '#363a4f', |
| 37 | + '--color-scrollbar-thumb': '#494d64', |
| 38 | + '--color-scrollbar-thumb-hover': '#a5adcb', |
| 39 | + '--color-button-download': '#8aadf4', |
| 40 | + '--color-button-download-hover': '#b5bfe2', |
| 41 | + '--color-button-download-text': '#24273a' |
| 42 | + }, |
| 43 | + frappe: { |
| 44 | + '--color-bg-dark': '#303446', |
| 45 | + '--color-bg-darker': '#232634', |
| 46 | + '--color-bg-medium': '#292c3c', |
| 47 | + '--color-bg-light': '#414559', |
| 48 | + '--color-border': '#51576d', |
| 49 | + '--color-text': '#c6d0f5', |
| 50 | + '--color-placeholder': '#a5adcb', |
| 51 | + '--color-hover': '#414559', |
| 52 | + '--color-hover-light': '#51576d', |
| 53 | + '--color-close-hover': '#e78284', |
| 54 | + '--color-scrollbar-bg': '#414559', |
| 55 | + '--color-scrollbar-thumb': '#51576d', |
| 56 | + '--color-scrollbar-thumb-hover': '#a5adcb', |
| 57 | + '--color-button-download': '#8caaee', |
| 58 | + '--color-button-download-hover': '#b5bfe2', |
| 59 | + '--color-button-download-text': '#303446' |
| 60 | + } |
| 61 | +}; |
| 62 | + |
6 | 63 | document.addEventListener("DOMContentLoaded", () => { |
7 | 64 | loadNotes(); |
8 | 65 | displayReleases(); |
9 | 66 | loadSettings(); |
10 | 67 | applyThemeFlavor(); // Apply the saved theme flavor on startup |
| 68 | + updateThemeDropdown(); |
11 | 69 |
|
12 | 70 | document.getElementById('appVersion').textContent = `Version: ${version}`; |
13 | 71 | document.getElementById('electronVersion').textContent = `Electron Version: ${electronVersion}`; |
@@ -97,7 +155,83 @@ function loadSettings() { |
97 | 155 |
|
98 | 156 | function applyThemeFlavor() { |
99 | 157 | const themeFlavor = localStorage.getItem('themeFlavor') || 'mocha'; |
100 | | - document.documentElement.setAttribute('data-theme', themeFlavor); |
| 158 | + loadTheme(themeFlavor); |
| 159 | +} |
| 160 | + |
| 161 | +function importTheme(event) { |
| 162 | + const file = event.target.files[0]; |
| 163 | + if (file) { |
| 164 | + const reader = new FileReader(); |
| 165 | + reader.onload = function(e) { |
| 166 | + try { |
| 167 | + const customThemes = JSON.parse(e.target.result); |
| 168 | + for (const [name, theme] of Object.entries(customThemes)) { |
| 169 | + saveCustomTheme(name, theme); |
| 170 | + } |
| 171 | + updateThemeDropdown(); |
| 172 | + alert('Themes imported successfully!'); |
| 173 | + } catch (error) { |
| 174 | + alert('Invalid JSON file.'); |
| 175 | + } |
| 176 | + }; |
| 177 | + reader.readAsText(file); |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +function deleteSelectedTheme() { |
| 182 | + const themeDropdown = document.getElementById('themeFlavor'); |
| 183 | + const selectedTheme = themeDropdown.value; |
| 184 | + const customThemes = getCustomThemes(); |
| 185 | + if (customThemes[selectedTheme]) { |
| 186 | + delete customThemes[selectedTheme]; |
| 187 | + localStorage.setItem('customThemes', JSON.stringify(customThemes)); |
| 188 | + updateThemeDropdown(); |
| 189 | + alert('Theme deleted successfully!'); |
| 190 | + } else { |
| 191 | + alert('Cannot delete default themes.'); |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +function updateThemeDropdown() { |
| 196 | + const themeDropdown = document.getElementById('themeFlavor'); |
| 197 | + const customThemes = getCustomThemes(); |
| 198 | + // Clear existing custom themes |
| 199 | + themeDropdown.querySelectorAll('.custom-theme').forEach(option => option.remove()); |
| 200 | + // Append custom themes |
| 201 | + for (const name of Object.keys(customThemes)) { |
| 202 | + const option = document.createElement('option'); |
| 203 | + option.value = name; |
| 204 | + option.textContent = name; |
| 205 | + option.classList.add('custom-theme'); |
| 206 | + themeDropdown.appendChild(option); |
| 207 | + } |
| 208 | +} |
| 209 | + |
| 210 | +function saveCustomTheme(name, theme) { |
| 211 | + const customThemes = JSON.parse(localStorage.getItem('customThemes')) || {}; |
| 212 | + customThemes[name] = theme; |
| 213 | + localStorage.setItem('customThemes', JSON.stringify(customThemes)); |
| 214 | +} |
| 215 | + |
| 216 | +function getCustomThemes() { |
| 217 | + return JSON.parse(localStorage.getItem('customThemes')) || {}; |
| 218 | +} |
| 219 | + |
| 220 | +function applyTheme(theme) { |
| 221 | + const root = document.documentElement; |
| 222 | + for (const [key, value] of Object.entries(theme)) { |
| 223 | + root.style.setProperty(key, value); |
| 224 | + } |
| 225 | +} |
| 226 | + |
| 227 | +function loadTheme(themeName) { |
| 228 | + const customThemes = getCustomThemes(); |
| 229 | + const theme = customThemes[themeName] || defaultThemes[themeName]; |
| 230 | + if (theme) { |
| 231 | + applyTheme(theme); |
| 232 | + } else { |
| 233 | + document.documentElement.setAttribute('data-theme', themeName); |
| 234 | + } |
101 | 235 | } |
102 | 236 |
|
103 | 237 | async function checkForUpdates() { |
|
0 commit comments