Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: allow using native titlebar on desktop app (#5826)

Abdullah Atta5672de856551
diff --git a/apps/desktop/src/api/os-integration.ts b/apps/desktop/src/api/os-integration.ts
index ac760e39a..28441312c 100644
--- a/apps/desktop/src/api/os-integration.ts
+++ b/apps/desktop/src/api/os-integration.ts
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { initTRPC } from "@trpc/server";
import { z } from "zod";
-import { dialog, nativeTheme, Notification, shell } from "electron";
+import { app, dialog, nativeTheme, Notification, shell } from "electron";
import { AutoLaunch } from "../utils/autolaunch";
import { config, DesktopIntegration } from "../utils/config";
import { bringToFront } from "../utils/bring-to-front";
@@ -152,6 +152,10 @@ export const osIntegrationRouter = t.router({
await rm(input);
}),
+ restart: t.procedure.query(() => {
+ app.relaunch();
+ app.exit();
+ }),
showNotification: t.procedure
.input(NotificationOptions)
.query(({ input }) => {
@@ -191,7 +195,10 @@ export const osIntegrationRouter = t.router({
({ input: { theme, windowControlsIconColor, backgroundColor } }) => {
if (windowControlsIconColor) {
config.windowControlsIconColor = windowControlsIconColor;
- if (process.platform === "win32")
+ if (
+ process.platform === "win32" &&
+ !config.desktopSettings.nativeTitlebar
+ )
globalThis.window?.setTitleBarOverlay({
symbolColor: windowControlsIconColor
});
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 5ca56e610..83b659dc2 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -84,17 +84,21 @@ async function createWindow() {
format: process.platform === "win32" ? "ico" : "png"
}),
- titleBarStyle: "hidden",
- frame: process.platform === "win32" || process.platform === "darwin",
- titleBarOverlay: {
- height: 37,
- color: "#00000000",
- symbolColor: config.windowControlsIconColor
- },
- trafficLightPosition: {
- x: 16,
- y: 12
- },
+ ...(config.desktopSettings.nativeTitlebar
+ ? {}
+ : {
+ titleBarStyle: "hidden",
+ frame: process.platform === "win32" || process.platform === "darwin",
+ titleBarOverlay: {
+ height: 37,
+ color: "#00000000",
+ symbolColor: config.windowControlsIconColor
+ },
+ trafficLightPosition: {
+ x: 16,
+ y: 12
+ }
+ }),
webPreferences: {
zoomFactor: config.zoomFactor,
diff --git a/apps/desktop/src/utils/config.ts b/apps/desktop/src/utils/config.ts
index 23a58a180..f1b3bcdaa 100644
--- a/apps/desktop/src/utils/config.ts
+++ b/apps/desktop/src/utils/config.ts
@@ -25,7 +25,8 @@ export const DesktopIntegration = z.object({
autoStart: z.boolean().optional(),
startMinimized: z.boolean().optional(),
minimizeToSystemTray: z.boolean().optional(),
- closeToSystemTray: z.boolean().optional()
+ closeToSystemTray: z.boolean().optional(),
+ nativeTitlebar: z.boolean().optional()
});
export type DesktopIntegration = z.infer<typeof DesktopIntegration>;
@@ -35,7 +36,8 @@ export const config = {
autoStart: false,
startMinimized: false,
minimizeToSystemTray: false,
- closeToSystemTray: false
+ closeToSystemTray: false,
+ nativeTitlebar: false
},
privacyMode: false,
isSpellCheckerEnabled: true,
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 72172c2d4..c224172ba 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -127,7 +127,7 @@ export default function TabsView() {
return (
<>
- {IS_DESKTOP_APP ? (
+ {!hasNativeTitlebar ? (
ReactDOM.createPortal(
<EditorActionBar />,
document.getElementById("titlebar-portal-container")!
diff --git a/apps/web/src/components/lightbox/index.tsx b/apps/web/src/components/lightbox/index.tsx
index 7855e4c7c..1088e5e7f 100644
--- a/apps/web/src/components/lightbox/index.tsx
+++ b/apps/web/src/components/lightbox/index.tsx
@@ -340,9 +340,9 @@ export class Lightbox extends React.Component<LightboxProps> {
overflow: "hidden",
alignItems: "center",
justifyContent: "flex-end",
- height: IS_DESKTOP_APP ? TITLE_BAR_HEIGHT : "auto",
+ height: !hasNativeTitlebar ? TITLE_BAR_HEIGHT : "auto",
pr:
- IS_DESKTOP_APP && getPlatform() !== "darwin"
+ !hasNativeTitlebar && getPlatform() !== "darwin"
? "calc(100vw - env(titlebar-area-width))"
: 0
}}
diff --git a/apps/web/src/dialogs/settings/desktop-integration-settings.ts b/apps/web/src/dialogs/settings/desktop-integration-settings.ts
index 56e39ca1f..c4486be3f 100644
--- a/apps/web/src/dialogs/settings/desktop-integration-settings.ts
+++ b/apps/web/src/dialogs/settings/desktop-integration-settings.ts
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { SettingsGroup } from "./types";
import { useStore as useSettingStore } from "../../stores/setting-store";
+import { showToast } from "../../utils/toast";
+import { desktop } from "../../common/desktop-bridge";
export const DesktopIntegrationSettings: SettingsGroup[] = [
{
@@ -126,6 +128,42 @@ export const DesktopIntegrationSettings: SettingsGroup[] = [
})
}
]
+ },
+ {
+ key: "use-native-titlebar",
+ title: "Use native titlebar",
+ description:
+ "Use native OS titlebar instead of replacing it with a custom one. Requires app restart for changes to take effect.",
+ onStateChange: (listener) =>
+ useSettingStore.subscribe(
+ (s) => s.desktopIntegrationSettings,
+ listener
+ ),
+ components: [
+ {
+ type: "toggle",
+ isToggled: () =>
+ !!useSettingStore.getState().desktopIntegrationSettings
+ ?.nativeTitlebar,
+ toggle: () => {
+ useSettingStore.getState().setDesktopIntegration({
+ nativeTitlebar:
+ !useSettingStore.getState().desktopIntegrationSettings
+ ?.nativeTitlebar
+ });
+ showToast(
+ "success",
+ "Restart the app for changes to take effect.",
+ [
+ {
+ text: "Restart now",
+ onClick: () => desktop?.integration.restart.query()
+ }
+ ]
+ );
+ }
+ }
+ ]
}
]
}
diff --git a/apps/web/src/global.d.ts b/apps/web/src/global.d.ts
index e32b66c14..f59e7b091 100644
--- a/apps/web/src/global.d.ts
+++ b/apps/web/src/global.d.ts
@@ -32,6 +32,7 @@ declare global {
var IS_BETA: boolean;
var APP_TITLE: string;
var IS_THEME_BUILDER: boolean;
+ var hasNativeTitlebar: boolean;
interface AuthenticationExtensionsClientInputs {
prf?: {
diff --git a/apps/web/src/hooks/use-window-controls.ts b/apps/web/src/hooks/use-window-controls.ts
index 1811999b1..6ae430073 100644
--- a/apps/web/src/hooks/use-window-controls.ts
+++ b/apps/web/src/hooks/use-window-controls.ts
@@ -50,6 +50,9 @@ export function useWindowControls() {
isMaximized,
isFullscreen,
hasNativeWindowControls:
- !IS_DESKTOP_APP || getPlatform() === "darwin" || getPlatform() === "win32"
+ !IS_DESKTOP_APP ||
+ hasNativeTitlebar ||
+ getPlatform() === "darwin" ||
+ getPlatform() === "win32"
};
}
diff --git a/apps/web/src/index.tsx b/apps/web/src/index.tsx
index e3e4f0d36..594f7fe1b 100644
--- a/apps/web/src/index.tsx
+++ b/apps/web/src/index.tsx
@@ -26,6 +26,7 @@ import { register } from "./utils/stream-saver/mitm";
import { getServiceWorkerVersion } from "./utils/version";
import { ErrorBoundary, ErrorComponent } from "./components/error-boundary";
import { TitleBar } from "./components/title-bar";
+import { desktop } from "./common/desktop-bridge";
renderApp();
@@ -34,6 +35,12 @@ async function renderApp() {
if (!rootElement) return;
const root = createRoot(rootElement);
+ window.hasNativeTitlebar =
+ !IS_DESKTOP_APP ||
+ !!(await desktop?.integration.desktopIntegration
+ .query()
+ ?.then((s) => s.nativeTitlebar));
+
try {
const { component, props, path } = await init();
@@ -47,7 +54,7 @@ async function renderApp() {
root.render(
<>
- {IS_DESKTOP_APP ? <TitleBar /> : null}
+ {hasNativeTitlebar ? null : <TitleBar />}
<ErrorBoundary>
<BaseThemeProvider
onRender={() => document.getElementById("splash")?.remove()}
@@ -63,7 +70,7 @@ async function renderApp() {
} catch (e) {
root.render(
<>
- {IS_DESKTOP_APP ? <TitleBar /> : null}
+ {hasNativeTitlebar ? null : <TitleBar />}
<ErrorComponent
error={e}
resetErrorBoundary={() => window.location.reload()}
diff --git a/apps/web/src/interfaces/key-store.ts b/apps/web/src/interfaces/key-store.ts
index ac1ad3ec8..b009bf0ea 100644
--- a/apps/web/src/interfaces/key-store.ts
+++ b/apps/web/src/interfaces/key-store.ts
@@ -123,8 +123,8 @@ const decoder = new TextDecoder();
*/
class KeyStore extends BaseStore<KeyStore> {
- #secretStore: IKVStore;
- #metadataStore: IKVStore;
+ #secretStore!: IKVStore;
+ #metadataStore!: IKVStore;
#keyId = "key";
#wrappingKeyId = "wrappingKey";
#key?: CryptoKey;
@@ -134,25 +134,25 @@ class KeyStore extends BaseStore<KeyStore> {
isLocked = false;
constructor(
- dbName: string,
+ private readonly dbName: string,
setState: SetState<KeyStore>,
get: GetState<KeyStore>
) {
super(setState, get);
+ }
+
+ activeCredentials = () => this.get().credentials.filter((c) => c.active);
+ init = async () => {
this.#metadataStore =
isFeatureSupported("indexedDB") && isFeatureSupported("clonableCryptoKey")
- ? new IndexedDBKVStore(`${dbName}-metadata`, "metadata")
+ ? new IndexedDBKVStore(`${this.dbName}-metadata`, "metadata")
: new MemoryKVStore();
this.#secretStore =
isFeatureSupported("indexedDB") && isFeatureSupported("clonableCryptoKey")
- ? new IndexedDBKVStore(`${dbName}-secrets`, "secrets")
+ ? new IndexedDBKVStore(`${this.dbName}-secrets`, "secrets")
: new MemoryKVStore();
- }
-
- activeCredentials = () => this.get().credentials.filter((c) => c.active);
- init = async () => {
const credentials = await this.getCredentials();
const secrets = Object.fromEntries(
await this.#secretStore.entries<EncryptedData>()