|
5 | 5 | import { PROJECTS_SERVICE } from '$lib/project/projectsService';
|
6 | 6 | import { projectSettingsPath } from '$lib/routes/routes.svelte';
|
7 | 7 | import { SETTINGS } from '$lib/settings/userSettings';
|
8 |
| - import { SHORTCUT_SERVICE } from '$lib/shortcuts/shortcutService.svelte'; |
| 8 | + import { SHORTCUT_SERVICE } from '$lib/shortcuts/shortcutService'; |
9 | 9 | import * as events from '$lib/utils/events';
|
10 |
| - import { unsubscribe } from '$lib/utils/unsubscribe'; |
11 | 10 | import { getEditorUri, openExternalUrl, showFileInFolder } from '$lib/utils/url';
|
12 | 11 | import { inject } from '@gitbutler/shared/context';
|
13 |
| - import { onMount } from 'svelte'; |
| 12 | + import { mergeUnlisten } from '@gitbutler/ui/utils/mergeUnlisten'; |
14 | 13 |
|
15 | 14 | const { projectId }: { projectId: string } = $props();
|
16 | 15 |
|
|
19 | 18 | const userSettings = inject(SETTINGS);
|
20 | 19 | const shortcutService = inject(SHORTCUT_SERVICE);
|
21 | 20 |
|
22 |
| - shortcutService.on('project-settings', () => { |
23 |
| - goto(projectSettingsPath(projectId)); |
24 |
| - }); |
25 |
| -
|
26 |
| - shortcutService.on('open-in-vscode', async () => { |
27 |
| - const project = await projectsService.fetchProject(projectId); |
28 |
| - if (!project) { |
29 |
| - throw new Error(`Project not found: ${projectId}`); |
30 |
| - } |
31 |
| - openExternalUrl( |
32 |
| - getEditorUri({ |
33 |
| - schemeId: $userSettings.defaultCodeEditor.schemeIdentifer, |
34 |
| - path: [vscodePath(project.path)], |
35 |
| - searchParams: { windowId: '_blank' } |
| 21 | + $effect(() => |
| 22 | + mergeUnlisten( |
| 23 | + shortcutService.on('project-settings', () => { |
| 24 | + goto(projectSettingsPath(projectId)); |
| 25 | + }), |
| 26 | + shortcutService.on('history', () => { |
| 27 | + $showHistoryView = !$showHistoryView; |
| 28 | + }), |
| 29 | + shortcutService.on('open-in-vscode', async () => { |
| 30 | + const project = await projectsService.fetchProject(projectId); |
| 31 | + if (!project) { |
| 32 | + throw new Error(`Project not found: ${projectId}`); |
| 33 | + } |
| 34 | + openExternalUrl( |
| 35 | + getEditorUri({ |
| 36 | + schemeId: $userSettings.defaultCodeEditor.schemeIdentifer, |
| 37 | + path: [vscodePath(project.path)], |
| 38 | + searchParams: { windowId: '_blank' } |
| 39 | + }) |
| 40 | + ); |
| 41 | + }), |
| 42 | + events.on('openHistory', () => { |
| 43 | + $showHistoryView = true; |
| 44 | + }), |
| 45 | + shortcutService.on('show-in-finder', async () => { |
| 46 | + const project = await projectsService.fetchProject(projectId); |
| 47 | + if (!project) { |
| 48 | + throw new Error(`Project not found: ${projectId}`); |
| 49 | + } |
| 50 | + // Show the project directory in the default file manager (cross-platform) |
| 51 | + await showFileInFolder(project.path); |
36 | 52 | })
|
37 |
| - ); |
38 |
| - }); |
39 |
| -
|
40 |
| - shortcutService.on('show-in-finder', async () => { |
41 |
| - const project = await projectsService.fetchProject(projectId); |
42 |
| - if (!project) { |
43 |
| - throw new Error(`Project not found: ${projectId}`); |
44 |
| - } |
45 |
| - // Show the project directory in the default file manager (cross-platform) |
46 |
| - await showFileInFolder(project.path); |
47 |
| - }); |
48 |
| -
|
49 |
| - shortcutService.on('history', () => { |
50 |
| - $showHistoryView = !$showHistoryView; |
51 |
| - }); |
52 |
| -
|
53 |
| - const unsubscribeHistoryButton = unsubscribe( |
54 |
| - events.on('openHistory', () => { |
55 |
| - $showHistoryView = true; |
56 |
| - }) |
| 53 | + ) |
57 | 54 | );
|
58 |
| -
|
59 |
| - onMount(() => { |
60 |
| - return () => { |
61 |
| - unsubscribeHistoryButton(); |
62 |
| - }; |
63 |
| - }); |
64 | 55 | </script>
|
0 commit comments