this repo has no description

delay if tabs aren't saved

phaz.uk 2a41e0b2 6f2f8a3e

verified
Changed files
+36 -1
src
Mangers
src-tauri
src
-1
src-tauri/src/lib.rs
··· 16 16 #[tokio::main] 17 17 pub async fn run() { 18 18 // TODO: Impl background running by default 19 - // TODO: Delay close if unsaved tabs 20 19 21 20 let container_folder = dirs::config_dir().unwrap().join("VRCMacros"); 22 21
+36
src/Mangers/NodeManager.tsx
··· 7 7 import { NodesByID } from "../Nodes/Nodes"; 8 8 import { save } from "@tauri-apps/plugin-dialog"; 9 9 import { ConfirmationManager } from "./ConfirmationManager"; 10 + import { getCurrentWindow } from "@tauri-apps/api/window"; 10 11 11 12 export interface TabHashMap { 12 13 [details: string] : Tab; ··· 40 41 })); 41 42 }; 42 43 }); 44 + 45 + (async () => { 46 + let window = await getCurrentWindow(); 47 + 48 + window.onCloseRequested(async ev => { 49 + ev.preventDefault(); 50 + 51 + let tabs = Object.values(this._tabs); 52 + let tabsNeedingSaving = tabs.filter(x => x.needsSave()); 53 + 54 + for(let tab of tabsNeedingSaving){ 55 + await new Promise<void>(res => { 56 + ConfirmationManager.Instance.ShowConfirmation( 57 + `Discard Changes in ${tab.name}?`, 58 + 'If you close this tab without saving you will lose all changes.', 59 + [ 60 + { 61 + text: 'Save', 62 + callback: async () => { 63 + await this.SaveTab(tab); 64 + res(); 65 + } 66 + }, 67 + { 68 + text: 'Don\'t Save', 69 + callback: () => { res(); } 70 + } 71 + ] 72 + ) 73 + }); 74 + } 75 + 76 + window.close(); 77 + }); 78 + })(); 43 79 } 44 80 45 81