elibroftw / modern-desktop-app-template

Tauri & ReactJS boilerplate for a modern desktop application. Not a project nor a substitute for my Tauri video tutorials.
https://www.youtube.com/playlist?list=PLmWYh0f8jKSjt9VC5sq2T3mFETasG2p2L
Creative Commons Zero v1.0 Universal
186 stars 38 forks source link

Fail to prompt to save / quit before closing window due to defect of `appWindow.close` #5

Open taodongl opened 1 year ago

taodongl commented 1 year ago

"onCloseRequested" can be caught if clicking "Close window" in taskbar, but it is bypassed if clicking customized "close" button in right-top of window

const unlisten = await appWindow.onCloseRequested(async (event) => {
    const confirmed = await confirm('Are you sure?');
    if (!confirmed) {
      event.preventDefault();
    } else {
      unlisten();
    }
  });

It is limitation of Tauri, Could you replace appWindow.close with other function? (I try to replace it with process.exit(), but it also cannot trigger 'tauri://close-requested' event :()

Refer to: https://github.com/tauri-apps/tauri/issues/5288#issuecomment-1261501470 Refer another: https://github.com/tauri-apps/plugins-workspace/issues/254

elibroftw commented 1 year ago

Modify titlebar.jsx to call your function manually before closing the window. At least until v2 is released. V2 should also add the tu title() function that is erroring at the moment.