mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 19:03:41 +00:00
Poll macOS system theme every 2 seconds in mac-system-theme extension
This commit is contained in:
parent
307f9b4169
commit
e5e944475d
1 changed files with 19 additions and 2 deletions
|
|
@ -18,8 +18,25 @@ function isDarkMode(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (pi: ExtensionAPI) {
|
export default function (pi: ExtensionAPI) {
|
||||||
|
let intervalId: ReturnType<typeof setInterval> | null = null;
|
||||||
|
|
||||||
pi.on("session_start", (_event, ctx) => {
|
pi.on("session_start", (_event, ctx) => {
|
||||||
const theme = isDarkMode() ? "dark" : "light";
|
let currentTheme = isDarkMode() ? "dark" : "light";
|
||||||
ctx.ui.setTheme(theme);
|
ctx.ui.setTheme(currentTheme);
|
||||||
|
|
||||||
|
intervalId = setInterval(() => {
|
||||||
|
const newTheme = isDarkMode() ? "dark" : "light";
|
||||||
|
if (newTheme !== currentTheme) {
|
||||||
|
currentTheme = newTheme;
|
||||||
|
ctx.ui.setTheme(currentTheme);
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
pi.on("session_shutdown", () => {
|
||||||
|
if (intervalId) {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
intervalId = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue