MCPcopy Create free account
hub / github.com/esengine/esengine / TauriDialogService

Class TauriDialogService

packages/editor-app/src/services/TauriDialogService.ts:28–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27@singleton()
28export class TauriDialogService implements IDialogExtended {
29 private showConfirmCallback?: (data: ConfirmDialogData) => void;
30 private locale: string = 'zh';
31
32 dispose(): void {
33 this.showConfirmCallback = undefined;
34 }
35
36 setConfirmCallback(callback: (data: ConfirmDialogData) => void): void {
37 this.showConfirmCallback = callback;
38 }
39
40 setLocale(locale: string): void {
41 this.locale = locale;
42 }
43
44 async openDialog(options: OpenDialogOptions): Promise<string | string[] | null> {
45 const result = await open({
46 multiple: options.multiple || false,
47 directory: options.directory || false,
48 filters: options.filters,
49 defaultPath: options.defaultPath,
50 title: options.title
51 });
52
53 return result;
54 }
55
56 async saveDialog(options: SaveDialogOptions): Promise<string | null> {
57 const result = await save({
58 filters: options.filters,
59 defaultPath: options.defaultPath,
60 title: options.title
61 });
62
63 return result;
64 }
65
66 async showMessage(title: string, messageText: string, type: 'info' | 'warning' | 'error' = 'info'): Promise<void> {
67 console.warn('[TauriDialogService] showMessage not implemented with custom UI, use notification instead');
68 }
69
70 async showConfirm(title: string, messageText: string): Promise<boolean> {
71 return new Promise((resolve) => {
72 if (this.showConfirmCallback) {
73 let resolved = false;
74 const handleResolve = (result: boolean) => {
75 if (!resolved) {
76 resolved = true;
77 resolve(result);
78 }
79 };
80
81 const localeKey = (this.locale in dialogTranslations ? this.locale : 'en') as LocaleKey;
82 const texts = dialogTranslations[localeKey];
83 const confirmText = texts.confirm;
84 const cancelText = texts.cancel;
85

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected