editor singleton added

This commit is contained in:
TheGB0077 2024-06-03 15:20:29 -03:00
parent 21d59b5e05
commit 908c6cdff7
2 changed files with 25 additions and 3 deletions

View File

@ -2,8 +2,8 @@
import { listen } from '$lib/backend/ipc'; import { listen } from '$lib/backend/ipc';
import { Project } from '$lib/backend/projects'; import { Project } from '$lib/backend/projects';
import { getContext } from '$lib/utils/context'; import { getContext } from '$lib/utils/context';
import { editor } from '$lib/utils/systemEditor';
import { open } from '@tauri-apps/api/shell'; import { open } from '@tauri-apps/api/shell';
import { invoke } from '@tauri-apps/api/tauri';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
@ -17,8 +17,7 @@
const unsubscribeOpenInVSCode = listen<string>( const unsubscribeOpenInVSCode = listen<string>(
'menu://project/open-in-vscode/clicked', 'menu://project/open-in-vscode/clicked',
async () => { async () => {
const editor = await invoke('resolve_vscode_variant'); const path = `${editor.get()}://file${project.path}`;
const path = `${editor}://file${project.path}`;
open(path); open(path);
} }
); );

View File

@ -0,0 +1,23 @@
import { invoke } from '@tauri-apps/api/tauri';
class SystemEditor {
constructor() {
this.resolveEditorVariant();
}
static instance = new SystemEditor();
private systemEditor = '';
async resolveEditorVariant() {
this.systemEditor = (await invoke('resolve_vscode_variant')) as string;
}
get() {
return this.systemEditor;
}
}
const editor = SystemEditor.instance;
export { editor };