Skip to content

Commit 58ac898

Browse files
authored
Merge pull request #9835 from gitbutlerapp/backend-refactor-homedir
Refactor backend, add homeDirectory to interface
2 parents 1e9ce59 + b87f950 commit 58ac898

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ export interface IBackend {
9898
documentDir: () => Promise<string>;
9999
joinPath: (path: string, ...paths: string[]) => Promise<string>;
100100
filePicker<T extends OpenDialogOptions>(options?: T): Promise<OpenDialogReturn<T>>;
101+
homeDirectory(): Promise<string>;
101102
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export default class Tauri implements IBackend {
3939
async filePicker<T extends OpenDialogOptions>() {
4040
return await filePickerTauri<T>();
4141
}
42+
async homeDirectory(): Promise<string> {
43+
// TODO: Find a workaround to avoid this dynamic import
44+
// https://github.com/sveltejs/kit/issues/905
45+
return await (await import('@tauri-apps/api/path')).homeDir();
46+
}
4247
}
4348

4449
async function tauriInvoke<T>(command: string, params: Record<string, unknown> = {}): Promise<T> {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ export default class Web implements IBackend {
1515
relaunch = webRelaunch;
1616
documentDir = webDocumentDir;
1717
joinPath = webJoinPath;
18+
homeDirectory = webHomeDirectory;
1819
async filePicker<T extends OpenDialogOptions>(options?: T): Promise<OpenDialogReturn<T>> {
1920
return await webFilePicker<T>(options);
2021
}
2122
}
2223

24+
async function webHomeDirectory(): Promise<string> {
25+
// This needs to be implemented for the web version
26+
return await Promise.resolve('/tmp/gitbutler');
27+
}
28+
2329
async function webJoinPath(pathSegment: string, ...paths: string[]): Promise<string> {
2430
// TODO: We might want to expose some endpoint in the backedn to handle path joining in the right way.
2531
// This will break on windows

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ export const csr = true;
2727

2828
// eslint-disable-next-line
2929
export const load: LayoutLoad = async () => {
30-
// TODO: Find a workaround to avoid this dynamic import
31-
// https://github.com/sveltejs/kit/issues/905
32-
let homeDir: string;
33-
if (import.meta.env.VITE_BUILD_TARGET === 'web') {
34-
homeDir = '/tmp/gitbutler';
35-
} else {
36-
homeDir = await (await import('@tauri-apps/api/path')).homeDir();
37-
}
38-
3930
const tokenMemoryService = new TokenMemoryService();
4031
const httpClient = new HttpClient(window.fetch, PUBLIC_API_BASE_URL, tokenMemoryService.token);
4132
const uploadsService = new UploadsService(httpClient);
@@ -58,6 +49,8 @@ export const load: LayoutLoad = async () => {
5849
const hooksService = new HooksService(backend);
5950
const userService = new UserService(backend, httpClient, tokenMemoryService, posthog);
6051

52+
const homeDir = await backend.homeDirectory();
53+
6154
// Await settings to prevent immediate reloads on initial render.
6255
await settingsService.refresh();
6356

0 commit comments

Comments
 (0)