Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
fix: closing wierd issue
Browse files Browse the repository at this point in the history
  • Loading branch information
krivahtoo committed May 18, 2023
1 parent 6b28239 commit f4b2b82
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use ipc::{
};
use server::start_server;
use state::AppState;
use std::{fs, path::PathBuf, sync::mpsc::sync_channel};
use std::{
fs,
path::PathBuf,
sync::{mpsc::sync_channel, Mutex},
};
use tauri::{Manager, WindowEvent};

mod error;
Expand All @@ -20,21 +24,25 @@ mod utils;

fn main() {
tracing_subscriber::fmt().init();
let exit = Mutex::new(false);

let (tx, rx) = sync_channel(1);
tauri::Builder::default()
.on_window_event(move |event| match event.window().label() {
"preview" => {
if let WindowEvent::CloseRequested { api, .. } = event.event() {
event.window().hide().unwrap();
api.prevent_close();
if !*exit.lock().unwrap() {
api.prevent_close();
}
}
}
"main" => {
if let WindowEvent::CloseRequested { .. } = event.event() {
if let Some(win) = event.window().get_window("preview") {
win.close().unwrap();
}
*exit.lock().unwrap() = true;
tx.send(1).expect("Failed to send close signal");
}
}
Expand Down

0 comments on commit f4b2b82

Please sign in to comment.