use tauri::menu::{Menu, MenuItem, Submenu};
use tauri::{AppHandle, Runtime};
use tauri_plugin_sparkle_updater::SparkleUpdaterExt;
pub const CHECK_FOR_UPDATES_ID: &str = "check-for-updates";
#[cfg(target_arch = "x86_64")]
const INTEL_FEED_URL: &str = "https://git.quineglobal.com/quine-global/homebrew-tap.git/tree/appcasts/quintodrome-x86_64.xml?raw=true";
pub fn setup<R: Runtime>(app: &AppHandle<R>) {
#[cfg(target_arch = "x86_64")]
if let Some(updater) = app.sparkle_updater() {
if let Err(err) = updater.set_feed_url_override(Some(INTEL_FEED_URL.to_string())) {
eprintln!("quintodrome: couldn't set the Intel appcast: {err}");
}
}
#[cfg(not(target_arch = "x86_64"))]
let _ = app;
}
pub fn menu<R: Runtime>(handle: &AppHandle<R>) -> tauri::Result<Menu<R>> {
let menu = Menu::default(handle)?;
let app_menu = menu
.items()?
.into_iter()
.next()
.and_then(|item| item.as_submenu().cloned());
if let Some(app_menu) = app_menu {
insert_check_for_updates(handle, &app_menu)?;
}
Ok(menu)
}
fn insert_check_for_updates<R: Runtime>(
handle: &AppHandle<R>,
app_menu: &Submenu<R>,
) -> tauri::Result<()> {
let item = MenuItem::with_id(
handle,
CHECK_FOR_UPDATES_ID,
"Check for Updatesβ¦",
true,
None::<&str>,
)?;
app_menu.insert(&item, 1)?;
Ok(())
}
pub fn check_for_updates<R: Runtime>(app: &AppHandle<R>) {
match app.sparkle_updater() {
Some(updater) => {
if let Err(err) = updater.check_for_updates() {
eprintln!("quintodrome: update check failed: {err}");
}
}
None => eprintln!("quintodrome: updates are only available in the packaged app"),
}
}