-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate module for settings window
- Loading branch information
1 parent
4f1c554
commit 042d615
Showing
8 changed files
with
140 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { Dependencies } from "@Core/Dependencies"; | ||
import type { DependencyRegistry } from "@Core/DependencyRegistry"; | ||
import { BrowserWindow } from "electron"; | ||
import { join } from "path"; | ||
|
||
export class SettingsWindowModule { | ||
public static async bootstrap(dependencyRegistry: DependencyRegistry<Dependencies>) { | ||
const ipcMain = dependencyRegistry.get("IpcMain"); | ||
|
||
let settingsWindow = await this.createSettingsWindow(dependencyRegistry); | ||
|
||
ipcMain.on("openSettings", async () => { | ||
if (settingsWindow.isDestroyed()) { | ||
settingsWindow = await this.createSettingsWindow(dependencyRegistry); | ||
} | ||
|
||
settingsWindow.focus(); | ||
settingsWindow.show(); | ||
}); | ||
} | ||
|
||
private static async createSettingsWindow( | ||
dependencyRegistry: DependencyRegistry<Dependencies>, | ||
): Promise<BrowserWindow> { | ||
const app = dependencyRegistry.get("App"); | ||
const environmentVariableProvider = dependencyRegistry.get("EnvironmentVariableProvider"); | ||
|
||
const settingsWindow = new BrowserWindow({ | ||
show: false, | ||
backgroundMaterial: "mica", | ||
autoHideMenuBar: true, | ||
webPreferences: { | ||
preload: join(__dirname, "..", "dist-preload", "index.js"), | ||
spellcheck: false, | ||
|
||
// The dev tools should only be available in development mode. Once the app is packaged, the dev tools | ||
// should be disabled. | ||
devTools: !app.isPackaged, | ||
|
||
// The following options are needed for images with `file://` URLs to work during development | ||
allowRunningInsecureContent: !app.isPackaged, | ||
webSecurity: app.isPackaged, | ||
}, | ||
}); | ||
|
||
if (app.isPackaged) { | ||
await settingsWindow.loadFile(join(__dirname, "..", "dist-renderer", "settings.html")); | ||
} else { | ||
await settingsWindow.loadURL( | ||
`${environmentVariableProvider.get("VITE_DEV_SERVER_URL")}/${"settings.html"}`, | ||
); | ||
} | ||
|
||
return settingsWindow; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./SettingsWindowModule"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,96 @@ | ||
import type { KeyboardEvent } from "react"; | ||
import { Route, Routes, useNavigate } from "react-router"; | ||
import { useScrollBar } from "@Core/Hooks"; | ||
import { useI18n } from "@Core/I18n"; | ||
import { getTheme } from "@Core/Theme"; | ||
import { ThemeContext } from "@Core/ThemeContext"; | ||
import { useAppCssProperties } from "@Core/useAppCssProperties"; | ||
import { FluentProvider, type Theme } from "@fluentui/react-components"; | ||
import { useEffect, useState } from "react"; | ||
import { Route, Routes } from "react-router"; | ||
import { ExtensionSettings } from "./ExtensionSettings"; | ||
import { Navigation } from "./Navigation"; | ||
import { settingsPages } from "./Pages"; | ||
import { SettingsHeader } from "./SettingsHeader"; | ||
|
||
export const Settings = () => { | ||
const navigate = useNavigate(); | ||
const closeSettings = () => navigate({ pathname: "/" }); | ||
const [theme, setTheme] = useState<Theme>(getTheme(window.ContextBridge)); | ||
|
||
const handleKeyDownEvent = (event: KeyboardEvent) => { | ||
if (event.key === "Escape") { | ||
event.preventDefault(); | ||
closeSettings(); | ||
} | ||
}; | ||
const [shouldPreferDarkColors, setShouldPreferDarkColors] = useState<boolean>( | ||
window.matchMedia("(prefers-color-scheme: dark)").matches, | ||
); | ||
|
||
return ( | ||
<div | ||
style={{ display: "flex", flexDirection: "column", height: "100%" }} | ||
onKeyDown={handleKeyDownEvent} | ||
tabIndex={-1} | ||
> | ||
<div style={{ flexShrink: 0 }}> | ||
<SettingsHeader onCloseSettingsClicked={closeSettings} /> | ||
</div> | ||
const { appCssProperties } = useAppCssProperties(); | ||
|
||
useI18n(); | ||
useScrollBar({ document, theme }); | ||
|
||
useEffect(() => { | ||
const nativeThemeChangedEventHandler = () => { | ||
setTheme(getTheme(window.ContextBridge)); | ||
setShouldPreferDarkColors(window.matchMedia("(prefers-color-scheme: dark)").matches); | ||
}; | ||
|
||
<div | ||
style={{ | ||
flexGrow: 1, | ||
display: "flex", | ||
flexDirection: "row", | ||
boxSizing: "border-box", | ||
height: "100%", | ||
width: "100%", | ||
overflow: "hidden", | ||
}} | ||
> | ||
<div style={{ display: "flex", flexShrink: 0 }}> | ||
window.ContextBridge.ipcRenderer.on("nativeThemeChanged", nativeThemeChangedEventHandler); | ||
|
||
return () => { | ||
window.ContextBridge.ipcRenderer.off("nativeThemeChanged", nativeThemeChangedEventHandler); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<ThemeContext.Provider value={{ theme, setTheme, shouldPreferDarkColors }}> | ||
<FluentProvider theme={theme} style={appCssProperties}> | ||
<div style={{ display: "flex", flexDirection: "column", height: "100%" }} tabIndex={-1}> | ||
<div | ||
style={{ | ||
flexGrow: 1, | ||
display: "flex", | ||
flexDirection: "column", | ||
padding: 10, | ||
gap: 20, | ||
flexDirection: "row", | ||
boxSizing: "border-box", | ||
overflowX: "auto", | ||
overflowY: "auto", | ||
height: "100%", | ||
width: "100%", | ||
overflow: "hidden", | ||
}} | ||
> | ||
<Navigation | ||
settingsPages={settingsPages} | ||
enabledExtensions={window.ContextBridge.getEnabledExtensions()} | ||
/> | ||
<div style={{ display: "flex", flexShrink: 0 }}> | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
padding: 10, | ||
gap: 20, | ||
boxSizing: "border-box", | ||
overflowX: "auto", | ||
overflowY: "auto", | ||
}} | ||
> | ||
<Navigation | ||
settingsPages={settingsPages} | ||
enabledExtensions={window.ContextBridge.getEnabledExtensions()} | ||
/> | ||
</div> | ||
</div> | ||
<div | ||
style={{ | ||
height: "100%", | ||
flexGrow: 1, | ||
overflowY: "auto", | ||
padding: 20, | ||
boxSizing: "border-box", | ||
}} | ||
> | ||
<Routes> | ||
{settingsPages.map(({ element, relativePath }) => ( | ||
<Route | ||
key={`settings-page-content-${relativePath}`} | ||
path={relativePath} | ||
element={element} | ||
/> | ||
))} | ||
<Route path="extension/:extensionId" element={<ExtensionSettings />} /> | ||
</Routes> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
style={{ | ||
height: "100%", | ||
flexGrow: 1, | ||
overflowY: "auto", | ||
padding: 20, | ||
boxSizing: "border-box", | ||
}} | ||
> | ||
<Routes> | ||
{settingsPages.map(({ element, relativePath }) => ( | ||
<Route | ||
key={`settings-page-content-${relativePath}`} | ||
path={relativePath} | ||
element={element} | ||
/> | ||
))} | ||
<Route path="extension/:extensionId" element={<ExtensionSettings />} /> | ||
</Routes> | ||
</div> | ||
</div> | ||
</div> | ||
</FluentProvider> | ||
</ThemeContext.Provider> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { Settings } from "@Core/Settings"; | ||
import { createRoot } from "react-dom/client"; | ||
import { HashRouter } from "react-router-dom"; | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
createRoot(document.getElementById("react-app") as HTMLDivElement).render( | ||
<HashRouter> | ||
<h1> Hello from settings </h1> | ||
<Settings /> | ||
</HashRouter>, | ||
); | ||
}); |