Skip to content

Commit

Permalink
feat: add option to configure close action
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <m@rtin.fyi>
  • Loading branch information
Martichou committed Mar 3, 2024
1 parent 5203a1e commit 64c1ca9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ A second workaround, you can download a Shortcut maker (see [here](https://xdafo

_Note: there's a current WIP to add a BLE advertisment in RQuickShare to overcome this._

### Once I close the app, it won't reopen

Make sure the app is really closed by running:
```
ps aux | grep r-quick-share
```
If you see that the process is still running, it's because the app is not closed. This may be an intended behavior: when closing the window, the app won't stop and instead is still running and accessible via the system tray icon. But if your distribution doesn't support/don't have enabled them, it may be an issue for you.

If you want to **really** close the app when clicking on the close button, you can change that inside the app by clicking on the three dots and then "Stop app on close".

WIP Notes
--------------------------
Expand Down
35 changes: 33 additions & 2 deletions frontend/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tauri::{AppHandle, Icon, Manager};
use tauri_plugin_autostart::MacosLauncher;
#[cfg(not(target_os = "linux"))]
use tauri_plugin_notification::NotificationExt;
use tauri_plugin_store::with_store;
use tokio::sync::{broadcast, mpsc};

use crate::logger::set_up_logging;
Expand Down Expand Up @@ -109,6 +110,7 @@ async fn main() -> Result<(), anyhow::Error> {
let state: tauri::State<'_, AppState> = app.state();
let _ = state.rqs.lock().unwrap().stop().await;

app.app_handle().cleanup_before_exit();
std::process::exit(0);
});
});
Expand Down Expand Up @@ -166,8 +168,37 @@ async fn main() -> Result<(), anyhow::Error> {
})
.on_window_event(|w, event| match event {
tauri::WindowEvent::CloseRequested { api, .. } => {
w.hide().unwrap();
api.prevent_close();
// This can never be an Err. We check for the realclose key, then convert the json to a bool
// and handle default to be "false".
let realclose = with_store(
w.app_handle().clone(),
w.state(),
".settings.json",
|store| {
return Ok(store
.get("realclose")
.and_then(|json| json.as_bool())
.unwrap_or(false));
},
)
.unwrap();

if !realclose {
trace!("Prevent close");
w.hide().unwrap();
api.prevent_close();
} else {
trace!("Real close");
tokio::task::block_in_place(|| {
tauri::async_runtime::block_on(async move {
let state: tauri::State<'_, AppState> = w.state();
let _ = state.rqs.lock().unwrap().stop().await;

w.app_handle().cleanup_before_exit();
std::process::exit(0);
});
});
}
}
_ => {}
})
Expand Down
32 changes: 26 additions & 6 deletions frontend/src/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@
</summary>
<ul class="mt-2 p-2 shadow menu dropdown-content z-[1] bg-base-100 rounded-box w-56">
<li>
<span class="active:!bg-green-100 active:!text-black" v-if="autostart" @click="setAutostart(false)">
Disable start on boot
</span>
<span class="active:!bg-green-100 active:!text-black" v-else @click="setAutostart(true)">
Enable start on boot
</span>
<div class="form-control active:!bg-green-100 active:!text-black w-52">
<label class="label cursor-pointer min-w-full">
<span class="label-text">Start on boot</span>
<input type="checkbox" :checked="autostart" class="checkbox checkbox-sm" @click="setAutostart(!autostart)">
</label>
</div>
</li>
<li>
<div class="form-control active:!bg-green-100 active:!text-black w-52">
<label class="label cursor-pointer min-w-full">
<span class="label-text">Keep running on close</span>
<input type="checkbox" :checked="!realclose" class="checkbox checkbox-sm" @click="setRealclose(!realclose)">
</label>
</div>
</li>
</ul>
</details>
Expand Down Expand Up @@ -315,6 +323,7 @@ interface DisplayedItem {
}

const autostartKey = "autostart";
const realcloseKey = "realclose";
const stateToDisplay: Array<Partial<State>> = ["ReceivedPairedKeyResult", "WaitingForUserConsent", "ReceivingFiles", "Disconnected", "Finished", "SentIntroduction", "SendingFiles", "Cancelled", "Rejected"]

export default {
Expand Down Expand Up @@ -343,6 +352,7 @@ export default {
version: opt<string>(),

autostart: ref<boolean>(true),
realclose: ref<boolean>(false),

hostname: ref<string>()
};
Expand All @@ -359,6 +369,8 @@ export default {
await this.applyAutostart();
}

this.getRealclose();

// Check permission for notification
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
Expand Down Expand Up @@ -529,6 +541,14 @@ export default {
await disable();
}
},
setRealclose: async function(realclose: boolean) {
await this.store.set(realcloseKey, realclose);
await this.store.save();
this.realclose = realclose;
},
getRealclose: async function() {
this.realclose = await this.store.get(realcloseKey) ?? false;
},
clearSending: async function() {
await invoke('stop_discovery');
this.outboundPayload = undefined;
Expand Down

0 comments on commit 64c1ca9

Please sign in to comment.