Skip to content

Commit

Permalink
Fix System Default theme not listening to system theme change (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
tupaschoal authored Dec 26, 2024
1 parent c9a2a01 commit f73b61d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion js/main-window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { app, BrowserWindow, dialog, ipcMain, Menu, shell, Tray } from 'electron';
import { app, BrowserWindow, dialog, ipcMain, Menu, nativeTheme, shell, Tray } from 'electron';
import path from 'path';
import Store from 'electron-store';

Expand Down Expand Up @@ -162,6 +162,16 @@ function createWindow()
}
});

// Listen for system theme changes in real-time
nativeTheme.on('updated', () =>
{
const savedPreferences = getUserPreferences();
const theme = savedPreferences['theme'];
if (theme === 'system-default')
{
mainWindow.webContents.send('RELOAD_THEME', theme);
}
});
}

function triggerStartupDialogs()
Expand Down
1 change: 1 addition & 0 deletions renderer/preload-scripts/calendar-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const calendarApi = {
handleWaiverSaved: (callback) => ipcRenderer.on('WAIVER_SAVED', callback),
handleCalendarReload: (callback) => ipcRenderer.on('RELOAD_CALENDAR', callback),
handlePunchDate: (callback) => ipcRenderer.on('PUNCH_DATE', callback),
handleThemeChange: (callback) => ipcRenderer.on('RELOAD_THEME', callback),
handleLeaveBy: (callback) => ipcRenderer.on('GET_LEAVE_BY', callback),
resizeMainWindow: () => resizeMainWindow(),
switchView: () => switchView(),
Expand Down
8 changes: 8 additions & 0 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ window.mainApi.handlePunchDate(() =>
calendar.punchDate();
});

/*
* Reload theme.
*/
window.mainApi.handleThemeChange(async(event, theme) =>
{
applyTheme(theme);
});

/*
* Returns value of "leave by" for notifications.
*/
Expand Down

0 comments on commit f73b61d

Please sign in to comment.