mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Signed automatic updates from GitHub Releases
- Atmosphere checks the repo's latest release and offers new versions with their notes - Updates are signed; installed copies refuse anything not signed with the project key - Installer, macOS and AppImage builds update themselves; portable and deb/rpm link to the download - Release workflow builds, signs and publishes every platform with latest.json on a version tag - Check-for-updates row and automatic check setting in Settings - Release guide in docs/releasing.md
This commit is contained in:
@@ -14,6 +14,7 @@ mod media;
|
||||
mod settings;
|
||||
mod storage;
|
||||
mod tagging;
|
||||
mod updates;
|
||||
|
||||
use base64::Engine as _;
|
||||
use downloader::{Downloader, JobRequest, SaveOptions};
|
||||
@@ -442,6 +443,7 @@ fn main() {
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.register_asynchronous_uri_scheme_protocol("atmo", |ctx, request, responder| {
|
||||
@@ -463,6 +465,9 @@ fn main() {
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
signin_check,
|
||||
updates::app_version,
|
||||
updates::update_check,
|
||||
updates::update_install,
|
||||
api_status,
|
||||
api_new_token,
|
||||
api_publish,
|
||||
|
||||
+4
-1
@@ -61,6 +61,7 @@ pub struct Settings {
|
||||
pub cookies_browser: String,
|
||||
pub cookies_file: String,
|
||||
pub api_enabled: bool,
|
||||
pub check_updates: bool,
|
||||
pub api_port: u16,
|
||||
pub api_read: bool,
|
||||
pub api_control: bool,
|
||||
@@ -106,6 +107,7 @@ impl Default for Settings {
|
||||
cookies_browser: String::new(),
|
||||
cookies_file: String::new(),
|
||||
api_enabled: false,
|
||||
check_updates: true,
|
||||
api_port: 47823,
|
||||
api_read: true,
|
||||
api_control: true,
|
||||
@@ -149,6 +151,7 @@ pub struct SettingsPatch {
|
||||
pub cookies_browser: Option<String>,
|
||||
pub cookies_file: Option<String>,
|
||||
pub api_enabled: Option<bool>,
|
||||
pub check_updates: Option<bool>,
|
||||
pub api_port: Option<u16>,
|
||||
pub api_read: Option<bool>,
|
||||
pub api_control: Option<bool>,
|
||||
@@ -201,7 +204,7 @@ impl Settings {
|
||||
($($f:ident),*) => { $( if let Some(v) = p.$f { self.$f = v; } )* };
|
||||
}
|
||||
set!(save_as, embed_metadata, collection_folders, number_tracks, skip_downloaded, sponsorblock, embed_subtitles, embed_chapters, watch_clipboard);
|
||||
set!(api_enabled, api_read, api_control, api_links);
|
||||
set!(api_enabled, api_read, api_control, api_links, check_updates);
|
||||
if let Some(p) = p.api_port.filter(|p| *p >= 1024) {
|
||||
self.api_port = p;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// atmosphere · updates.rs · Checks GitHub Releases for signed updates and installs them, or links to the download where self-update isn't possible
|
||||
use crate::{err, AppState, CmdResult};
|
||||
use serde::Serialize;
|
||||
use tauri::{AppHandle, Emitter, State};
|
||||
use tauri_plugin_updater::UpdaterExt;
|
||||
|
||||
pub const RELEASES: &str = "https://github.com/pvrzz/atmosphere/releases/latest";
|
||||
const PROGRESS_EVENT: &str = "atmosphere://update";
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateInfo {
|
||||
version: String,
|
||||
current: String,
|
||||
notes: Option<String>,
|
||||
date: Option<String>,
|
||||
can_install: bool,
|
||||
page: String,
|
||||
}
|
||||
|
||||
pub fn can_self_update() -> bool {
|
||||
if crate::engine::portable_root().is_some() {
|
||||
return false;
|
||||
}
|
||||
if cfg!(target_os = "linux") {
|
||||
return std::env::var_os("APPIMAGE").is_some();
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn app_version(app: AppHandle) -> serde_json::Value {
|
||||
serde_json::json!({ "version": app.package_info().version.to_string(), "canSelfUpdate": can_self_update(), "page": RELEASES })
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_check(app: AppHandle) -> CmdResult<Option<UpdateInfo>> {
|
||||
let updater = app.updater().map_err(|e| e.to_string())?;
|
||||
let found = match updater.check().await {
|
||||
Ok(found) => found,
|
||||
Err(tauri_plugin_updater::Error::ReleaseNotFound) => None,
|
||||
Err(e) => return Err(format!("Couldn't reach GitHub to check for updates ({e})")),
|
||||
};
|
||||
Ok(found.map(|u| UpdateInfo {
|
||||
version: u.version.clone(),
|
||||
current: u.current_version.clone(),
|
||||
notes: u.body.clone().filter(|b| !b.trim().is_empty()),
|
||||
date: u.date.map(|d| d.to_string()),
|
||||
can_install: can_self_update(),
|
||||
page: RELEASES.into(),
|
||||
}))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_install(app: AppHandle, state: State<'_, AppState>) -> CmdResult<()> {
|
||||
if !can_self_update() {
|
||||
return Err("This copy of Atmosphere can't update itself. Download the new version instead.".into());
|
||||
}
|
||||
let update = app
|
||||
.updater()
|
||||
.map_err(|e| e.to_string())?
|
||||
.check()
|
||||
.await
|
||||
.map_err(|e| format!("Couldn't check for updates ({e})"))?
|
||||
.ok_or("Atmosphere is already up to date.")?;
|
||||
state.dl.cancel_all();
|
||||
let mut received: u64 = 0;
|
||||
let progress = app.clone();
|
||||
update
|
||||
.download_and_install(
|
||||
move |chunk, total| {
|
||||
received += chunk as u64;
|
||||
let _ = progress.emit(PROGRESS_EVENT, serde_json::json!({ "received": received, "total": total }));
|
||||
},
|
||||
|| {},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| err(anyhow::anyhow!("The update couldn't be installed ({e})")))?;
|
||||
crate::storage::wipe_temp();
|
||||
app.restart();
|
||||
}
|
||||
Reference in New Issue
Block a user