Skip to content

Commit 0353fd3

Browse files
committed
Adjust code around window titles code just a bit
1 parent cbd13ee commit 0353fd3

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

apps/desktop/src/lib/backend/backend.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export interface IBackend {
6969
* Loads a disk store from a file.
7070
*/
7171
loadDiskStore: (fileName: string) => Promise<DiskStore>;
72+
/**
73+
* Gets the window title.
74+
*/
75+
getWindowTitle: () => Promise<string>;
7276
/**
7377
* Sets the window title.
7478
*/

apps/desktop/src/lib/backend/tauri.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { EventCallback, EventName } from '@tauri-apps/api/event';
2323
export default class Tauri implements IBackend {
2424
platformName = platform();
2525
private appWindow: Window | undefined;
26+
2627
systemTheme = readable<string | null>(null, (set) => {
2728
if (!this.appWindow) {
2829
this.appWindow = getCurrentWindow();
@@ -35,6 +36,7 @@ export default class Tauri implements IBackend {
3536
set(e.payload);
3637
});
3738
});
39+
3840
invoke = tauriInvoke;
3941
listen = tauriListen;
4042
checkUpdate = tauriCheck;
@@ -47,18 +49,29 @@ export default class Tauri implements IBackend {
4749
getAppInfo = tauriGetAppInfo;
4850
readTextFromClipboard = tauriReadText;
4951
writeTextToClipboard = tauriWriteText;
52+
5053
async filePicker<T extends OpenDialogOptions>(options?: T) {
5154
return await filePickerTauri<T>(options);
5255
}
56+
5357
async homeDirectory(): Promise<string> {
5458
// TODO: Find a workaround to avoid this dynamic import
5559
// https://github.com/sveltejs/kit/issues/905
5660
return await (await import('@tauri-apps/api/path')).homeDir();
5761
}
62+
5863
async loadDiskStore(fileName: string): Promise<DiskStore> {
5964
const store = await Store.load(fileName, { autoSave: true });
6065
return new TauriDiskStore(store);
6166
}
67+
68+
async getWindowTitle(): Promise<string> {
69+
if (!this.appWindow) {
70+
this.appWindow = getCurrentWindow();
71+
}
72+
return await this.appWindow.title();
73+
}
74+
6275
setWindowTitle(title: string): void {
6376
if (!this.appWindow) {
6477
this.appWindow = getCurrentWindow();

apps/desktop/src/lib/backend/web.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export default class Web implements IBackend {
3232
// For the web version, we don't have a disk store, so we return a no-op implementation
3333
return new WebDiskStore();
3434
}
35+
36+
async getWindowTitle(): Promise<string> {
37+
return await Promise.resolve(document.title);
38+
}
39+
3540
setWindowTitle(title: string): void {
3641
document.title = title;
3742
}

apps/desktop/src/routes/+layout.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@
7474
const shortcutService = inject(SHORTCUT_SERVICE);
7575
$effect(() => shortcutService.listen());
7676
77-
// Reset window title when not in a project
78-
$effect(() => {
79-
if (!projectId) {
80-
backend.setWindowTitle('GitButler');
81-
}
82-
});
83-
8477
// =============================================================================
8578
// ANALYTICS & NAVIGATION
8679
// =============================================================================
@@ -176,6 +169,10 @@
176169
onkeydown={handleKeyDown}
177170
/>
178171

172+
<svelte:head>
173+
<title>GitButler</title>
174+
</svelte:head>
175+
179176
<div class="app-root" role="application" oncontextmenu={(e) => !dev && e.preventDefault()}>
180177
{@render children()}
181178
</div>

apps/desktop/src/routes/[projectId]/+layout.svelte

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,17 @@
174174
175175
const backend = inject(BACKEND);
176176
$effect(() => {
177-
if (currentProject?.title) {
178-
backend.setWindowTitle(`${currentProject.title} — GitButler`);
179-
} else {
180-
backend.setWindowTitle('GitButler');
181-
}
177+
let windowTitle: string;
178+
const projectTitle = currentProject?.title;
179+
180+
backend.getWindowTitle().then((value) => {
181+
windowTitle = value;
182+
if (projectTitle) backend.setWindowTitle(`${projectTitle} — ${value}`);
183+
});
184+
185+
return () => {
186+
if (windowTitle) backend.setWindowTitle(windowTitle);
187+
};
182188
});
183189
184190
// =============================================================================

0 commit comments

Comments
 (0)