Skip to content

Commit e69578c

Browse files
committed
Custom URL service
1 parent c0a3806 commit e69578c

23 files changed

+104
-61
lines changed

apps/desktop/src/components/BranchHeaderContextMenu.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import { projectAiGenEnabled } from '$lib/config/config';
2525
import { DEFAULT_FORGE_FACTORY } from '$lib/forge/forgeFactory.svelte';
2626
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
27-
import { openExternalUrl } from '$lib/utils/url';
27+
import { URL_SERVICE } from '$lib/utils/url';
2828
import { inject } from '@gitbutler/shared/context';
2929
import {
3030
ContextMenu,
@@ -57,6 +57,7 @@
5757
const stackService = inject(STACK_SERVICE);
5858
const forge = inject(DEFAULT_FORGE_FACTORY);
5959
const promptService = inject(PROMPT_SERVICE);
60+
const urlService = inject(URL_SERVICE);
6061
const [insertBlankCommitInBranch, commitInsertion] = stackService.insertBlankCommit;
6162
const [updateBranchNameMutation] = stackService.updateBranchName;
6263
const [createRef, refCreation] = stackService.createReference;
@@ -177,7 +178,7 @@
177178
testId={TestId.BranchHeaderContextMenu_OpenInBrowser}
178179
onclick={() => {
179180
const url = forge.current.branch(branchName)?.url;
180-
if (url) openExternalUrl(url);
181+
if (url) urlService.openExternalUrl(url);
181182
close();
182183
}}
183184
/>
@@ -295,7 +296,7 @@
295296
label="Open PR in browser"
296297
testId={TestId.BranchHeaderContextMenu_OpenPRInBrowser}
297298
onclick={() => {
298-
openExternalUrl(pr.htmlUrl);
299+
urlService.openExternalUrl(pr.htmlUrl);
299300
close();
300301
}}
301302
/>

apps/desktop/src/components/BranchList.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
1919
import { combineResults } from '$lib/state/helpers';
2020
import { UI_STATE } from '$lib/state/uiState.svelte';
21-
import { openExternalUrl } from '$lib/utils/url';
21+
import { URL_SERVICE } from '$lib/utils/url';
2222
import { copyToClipboard } from '@gitbutler/shared/clipboard';
2323
import { inject } from '@gitbutler/shared/context';
2424
@@ -42,6 +42,7 @@
4242
const uiState = inject(UI_STATE);
4343
const modeService = inject(MODE_SERVICE);
4444
const forge = inject(DEFAULT_FORGE_FACTORY);
45+
const urlService = inject(URL_SERVICE);
4546
const intelligentScrollingService = inject(INTELLIGENT_SCROLLING_SERVICE);
4647
4748
const [insertBlankCommitInBranch, commitInsertion] = stackService.insertBlankCommit;
@@ -261,7 +262,7 @@
261262
disabled={!prUrl}
262263
onclick={() => {
263264
if (prUrl) {
264-
openExternalUrl(prUrl);
265+
urlService.openExternalUrl(prUrl);
265266
}
266267
}}
267268
icon={forge.current.name === 'gitlab' ? 'view-mr-browser' : 'view-pr-browser'}

apps/desktop/src/components/CommitContextMenu.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import { writeClipboard } from '$lib/backend/clipboard';
4646
import { rewrapCommitMessage } from '$lib/config/uiFeatureFlags';
4747
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
48-
import { openExternalUrl } from '$lib/utils/url';
48+
import { URL_SERVICE } from '$lib/utils/url';
4949
import { inject } from '@gitbutler/shared/context';
5050
import {
5151
ContextMenu,
@@ -66,6 +66,7 @@
6666
6767
let { flat, projectId, openId = $bindable(), rightClickTrigger, contextData }: Props = $props();
6868
69+
const urlService = inject(URL_SERVICE);
6970
const stackService = inject(STACK_SERVICE);
7071
const [insertBlankCommitInBranch, commitInsertion] = stackService.insertBlankCommit;
7172
const [createRef, refCreation] = stackService.createReference;
@@ -164,7 +165,7 @@
164165
<ContextMenuItem
165166
label="Open in browser"
166167
onclick={async () => {
167-
await openExternalUrl(commitUrl);
168+
await urlService.openExternalUrl(commitUrl);
168169
close();
169170
}}
170171
/>

apps/desktop/src/components/DecorativeSplitView.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import AccountLink from '$components/AccountLink.svelte';
33
import gbLogoSvg from '$lib/assets/gb-logo.svg?raw';
44
import { USER } from '$lib/user/user';
5-
import { openExternalUrl } from '$lib/utils/url';
5+
import { URL_SERVICE } from '$lib/utils/url';
66
import { inject } from '@gitbutler/shared/context';
77
import { Icon } from '@gitbutler/ui';
88
import { type Snippet } from 'svelte';
@@ -17,6 +17,7 @@
1717
const { hideDetails, img, children, testId }: Props = $props();
1818
1919
const user = inject(USER);
20+
const urlService = inject(URL_SERVICE);
2021
</script>
2122

2223
<div class="decorative-split-view" data-testid={testId}>
@@ -51,15 +52,17 @@
5152
<button
5253
type="button"
5354
class="right-side__link"
54-
onclick={async () => await openExternalUrl('https://docs.gitbutler.com/')}
55+
onclick={async () =>
56+
await urlService.openExternalUrl('https://docs.gitbutler.com/')}
5557
>
5658
<Icon name="docs" opacity={0.6} />
5759
<span class="text-14 text-semibold">GitButler docs</span>
5860
</button>
5961
<button
6062
type="button"
6163
class="right-side__link"
62-
onclick={async () => await openExternalUrl('https://discord.com/invite/MmFkmaJ42D')}
64+
onclick={async () =>
65+
await urlService.openExternalUrl('https://discord.com/invite/MmFkmaJ42D')}
6366
>
6467
<Icon name="discord" opacity={0.6} />
6568
<span class="text-14 text-semibold">Join community</span>

apps/desktop/src/components/EditMode.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { SETTINGS } from '$lib/settings/userSettings';
1717
import { USER_SERVICE } from '$lib/user/userService';
1818
import { computeChangeStatus } from '$lib/utils/fileStatus';
19-
import { getEditorUri, openExternalUrl } from '$lib/utils/url';
19+
import { getEditorUri, URL_SERVICE } from '$lib/utils/url';
2020
import { inject } from '@gitbutler/shared/context';
2121
2222
import { Avatar, Badge, Button, FileListItem, InfoButton, Modal } from '@gitbutler/ui';
@@ -42,6 +42,7 @@
4242
const modeService = inject(MODE_SERVICE);
4343
const userSettings = inject(SETTINGS);
4444
const fileService = inject(FILE_SERVICE);
45+
const urlService = inject(URL_SERVICE);
4546
4647
const userService = inject(USER_SERVICE);
4748
const user = userService.user;
@@ -208,7 +209,7 @@
208209
schemeId: $userSettings.defaultCodeEditor.schemeIdentifer,
209210
path: [vscodePath(projectPath), file.path]
210211
});
211-
openExternalUrl(path);
212+
urlService.openExternalUrl(path);
212213
}
213214
}
214215

apps/desktop/src/components/FileContextMenu.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
1717
import { UI_STATE } from '$lib/state/uiState.svelte';
1818
import { computeChangeStatus } from '$lib/utils/fileStatus';
19-
import { getEditorUri, openExternalUrl } from '$lib/utils/url';
19+
import { getEditorUri, URL_SERVICE } from '$lib/utils/url';
2020
import { inject } from '@gitbutler/shared/context';
2121
2222
import {
@@ -63,6 +63,7 @@
6363
const aiService = inject(AI_SERVICE);
6464
const actionService = inject(ACTION_SERVICE);
6565
const fileService = inject(FILE_SERVICE);
66+
const urlService = inject(URL_SERVICE);
6667
const [autoCommit, autoCommitting] = actionService.autoCommit;
6768
const [branchChanges, branchingChanges] = actionService.branchChanges;
6869
const [absorbChanges, absorbingChanges] = actionService.absorb;
@@ -425,7 +426,7 @@
425426
schemeId: $userSettings.defaultCodeEditor.schemeIdentifer,
426427
path: [vscodePath(projectPath), change.path]
427428
});
428-
openExternalUrl(path);
429+
urlService.openExternalUrl(path);
429430
}
430431
}
431432
contextMenu.close();

apps/desktop/src/components/GithubIntegration.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { writeClipboard } from '$lib/backend/clipboard';
33
import { GITHUB_USER_SERVICE } from '$lib/forge/github/githubUserService.svelte';
44
import { USER_SERVICE } from '$lib/user/userService';
5-
import { openExternalUrl } from '$lib/utils/url';
5+
import { URL_SERVICE } from '$lib/utils/url';
66
import { inject } from '@gitbutler/shared/context';
77
88
import { Button, Icon, Modal, SectionCard, chipToasts as toasts } from '@gitbutler/ui';
@@ -18,6 +18,7 @@
1818
const githubUserService = inject(GITHUB_USER_SERVICE);
1919
const userService = inject(USER_SERVICE);
2020
const user = userService.user;
21+
const urlService = inject(URL_SERVICE);
2122
2223
// step flags
2324
let codeCopied = $state(false);
@@ -160,7 +161,7 @@
160161
disabled={GhActivationLinkPressed}
161162
icon="open-link"
162163
onclick={() => {
163-
openExternalUrl('https://github.com/login/device');
164+
urlService.openExternalUrl('https://github.com/login/device');
164165
GhActivationLinkPressed = true;
165166

166167
// add timeout to prevent show the check button before the page is opened

apps/desktop/src/components/HunkContextMenu.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import { PROJECTS_SERVICE } from '$lib/project/projectsService';
2020
import { SETTINGS } from '$lib/settings/userSettings';
2121
import { STACK_SERVICE } from '$lib/stacks/stackService.svelte';
22-
import { getEditorUri, openExternalUrl } from '$lib/utils/url';
22+
import { getEditorUri, URL_SERVICE } from '$lib/utils/url';
2323
import { inject } from '@gitbutler/shared/context';
2424
import { ContextMenu, ContextMenuItem, ContextMenuSection, TestId } from '@gitbutler/ui';
2525
import type { TreeChange } from '$lib/hunks/change';
@@ -50,6 +50,7 @@
5050
const stackService = inject(STACK_SERVICE);
5151
const ircService = inject(IRC_SERVICE);
5252
const projectService = inject(PROJECTS_SERVICE);
53+
const urlService = inject(URL_SERVICE);
5354
5455
const userSettings = inject(SETTINGS);
5556
const ircChats = $derived(ircService.getChats());
@@ -174,7 +175,7 @@
174175
path: [vscodePath(project.path), filePath],
175176
line: item.beforeLineNumber ?? item.afterLineNumber
176177
});
177-
openExternalUrl(path);
178+
urlService.openExternalUrl(path);
178179
}
179180
contextMenu?.close();
180181
}}

apps/desktop/src/components/IconLink.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
2-
import { openExternalUrl } from '$lib/utils/url';
3-
2+
import { URL_SERVICE } from '$lib/utils/url';
3+
import { inject } from '@gitbutler/shared/context';
44
import { Icon } from '@gitbutler/ui';
55
import type iconsJson from '@gitbutler/ui/data/icons.json';
66
import type { Snippet } from 'svelte';
@@ -12,9 +12,10 @@
1212
}
1313
1414
const { href, icon, children }: Props = $props();
15+
const urlService = inject(URL_SERVICE);
1516
</script>
1617

17-
<button type="button" class="link" onclick={async () => await openExternalUrl(href)}>
18+
<button type="button" class="link" onclick={async () => await urlService.openExternalUrl(href)}>
1819
<Icon name={icon} />
1920
<span class="text-12">
2021
{@render children()}

apps/desktop/src/components/IntegrateUpstreamModal.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
type StackStatusesWithBranchesV3
1717
} from '$lib/upstream/types';
1818
import { UPSTREAM_INTEGRATION_SERVICE } from '$lib/upstream/upstreamIntegrationService.svelte';
19-
import { openExternalUrl } from '$lib/utils/url';
19+
import { URL_SERVICE } from '$lib/utils/url';
2020
import { inject } from '@gitbutler/shared/context';
2121
import {
2222
Badge,
@@ -51,6 +51,7 @@
5151
const baseBranchService = inject(BASE_BRANCH_SERVICE);
5252
const baseBranchResponse = $derived(baseBranchService.baseBranch(projectId));
5353
const base = $derived(baseBranchResponse.current.data);
54+
const urlService = inject(URL_SERVICE);
5455
5556
let modal = $state<Modal>();
5657
let integratingUpstream = $state<OperationState>('inert');
@@ -321,7 +322,7 @@
321322
date={commit.createdAt}
322323
author={commit.author.name}
323324
url={commitUrl}
324-
onOpen={(url) => openExternalUrl(url)}
325+
onOpen={(url) => urlService.openExternalUrl(url)}
325326
onCopy={() => writeClipboard(commit.id)}
326327
/>
327328
{/each}

0 commit comments

Comments
 (0)