|
195 | 195 | '../wailsjs/runtime/runtime' |
196 | 196 | ); |
197 | 197 |
|
198 | | - // Apply theme colors from aether.override.css as CSS custom properties |
199 | | - EventsOn( |
200 | | - 'theme-colors-changed', |
201 | | - (colors: Record<string, string>) => { |
202 | | - const root = document.documentElement; |
203 | | - for (const [name, value] of Object.entries(colors)) { |
204 | | - root.style.setProperty(`--aether-${name}`, value); |
205 | | - } |
206 | | - // Map key GTK colors to our Tailwind theme tokens |
207 | | - if (colors.background) { |
208 | | - root.style.setProperty( |
209 | | - '--color-bg-primary', |
210 | | - colors.background |
211 | | - ); |
212 | | - root.style.setProperty( |
213 | | - '--color-bg-secondary', |
214 | | - colors.background |
215 | | - ); |
216 | | - document.body.style.background = colors.background; |
217 | | - // Update native window/titlebar color to match theme |
218 | | - const rgb = hexToRgb(colors.background); |
219 | | - WindowSetBackgroundColour(rgb.r, rgb.g, rgb.b, 255); |
220 | | - } |
221 | | - if (colors.foreground) { |
222 | | - root.style.setProperty( |
223 | | - '--color-fg-primary', |
224 | | - colors.foreground |
225 | | - ); |
226 | | - document.body.style.color = colors.foreground; |
227 | | - } |
228 | | - if (colors.blue) { |
229 | | - root.style.setProperty( |
230 | | - '--color-accent', |
231 | | - colors.blue |
232 | | - ); |
233 | | - } |
234 | | - if (colors.red) { |
235 | | - root.style.setProperty( |
236 | | - '--color-destructive', |
237 | | - colors.red |
238 | | - ); |
239 | | - } |
240 | | - if (colors.green) { |
241 | | - root.style.setProperty( |
242 | | - '--color-success', |
243 | | - colors.green |
244 | | - ); |
245 | | - } |
246 | | - if (colors.yellow) { |
247 | | - root.style.setProperty( |
248 | | - '--color-warning', |
249 | | - colors.yellow |
250 | | - ); |
251 | | - } |
252 | | - // Cache for instant restore on next launch |
253 | | - try { |
254 | | - localStorage.setItem( |
255 | | - 'aether-theme-colors', |
256 | | - JSON.stringify(colors) |
257 | | - ); |
258 | | - } catch {} |
| 198 | + const applyThemeColors = (colors: Record<string, string>) => { |
| 199 | + const root = document.documentElement; |
| 200 | + for (const [name, value] of Object.entries(colors)) { |
| 201 | + root.style.setProperty(`--aether-${name}`, value); |
259 | 202 | } |
260 | | - ); |
| 203 | + if (colors.background) { |
| 204 | + root.style.setProperty( |
| 205 | + '--color-bg-primary', |
| 206 | + colors.background |
| 207 | + ); |
| 208 | + root.style.setProperty( |
| 209 | + '--color-bg-secondary', |
| 210 | + colors.background |
| 211 | + ); |
| 212 | + document.body.style.background = colors.background; |
| 213 | + const rgb = hexToRgb(colors.background); |
| 214 | + WindowSetBackgroundColour(rgb.r, rgb.g, rgb.b, 255); |
| 215 | + } |
| 216 | + if (colors.foreground) { |
| 217 | + root.style.setProperty( |
| 218 | + '--color-fg-primary', |
| 219 | + colors.foreground |
| 220 | + ); |
| 221 | + document.body.style.color = colors.foreground; |
| 222 | + } |
| 223 | + if (colors.blue) { |
| 224 | + root.style.setProperty('--color-accent', colors.blue); |
| 225 | + } |
| 226 | + if (colors.red) { |
| 227 | + root.style.setProperty( |
| 228 | + '--color-destructive', |
| 229 | + colors.red |
| 230 | + ); |
| 231 | + } |
| 232 | + if (colors.green) { |
| 233 | + root.style.setProperty('--color-success', colors.green); |
| 234 | + } |
| 235 | + if (colors.yellow) { |
| 236 | + root.style.setProperty( |
| 237 | + '--color-warning', |
| 238 | + colors.yellow |
| 239 | + ); |
| 240 | + } |
| 241 | + // Read synchronously by index.html at first paint to |
| 242 | + // avoid a flash before the Wails bridge is ready. |
| 243 | + try { |
| 244 | + localStorage.setItem( |
| 245 | + 'aether-theme-colors', |
| 246 | + JSON.stringify(colors) |
| 247 | + ); |
| 248 | + } catch {} |
| 249 | + }; |
| 250 | +
|
| 251 | + EventsOn('theme-colors-changed', applyThemeColors); |
| 252 | +
|
| 253 | + // Pull before subscribing-is-too-late: EventsOn attaches |
| 254 | + // after the watcher's startup emit has already fired. |
| 255 | + try { |
| 256 | + const {GetThemeColors} = await import( |
| 257 | + '../wailsjs/go/main/App' |
| 258 | + ); |
| 259 | + const colors = await GetThemeColors(); |
| 260 | + if (colors && Object.keys(colors).length > 0) { |
| 261 | + applyThemeColors(colors); |
| 262 | + } |
| 263 | + } catch {} |
261 | 264 |
|
262 | 265 | // Listen for IPC remote control state changes |
263 | 266 | EventsOn( |
|
0 commit comments