Skip to content

Commit

Permalink
Version bump. Updating logic in place on app startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianPayne committed Nov 18, 2024
1 parent 4dbf660 commit c6af5a2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ennesults-rs",
"private": true,
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ennesults-rs"
version = "0.2.0"
version = "0.2.1"
description = "A Twitch bot created for Ennegineer to kindly insult her chat."
authors = ["Christian Payne"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/capabilities/desktop.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"identifier": "desktop-capability",
"identifier": "desktop",
"platforms": [
"macOS",
"windows",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/gen/schemas/capabilities.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"permissions":["updater:default"],"platforms":["macOS","windows","linux"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","fs:allow-read-file","fs:allow-write-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":["$APP/*","$DESKTOP/*"]},"shell:allow-open","fs:default","shell:default"]}}
{"desktop":{"identifier":"desktop","description":"","local":true,"permissions":["updater:default"],"platforms":["macOS","windows","linux"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","fs:allow-read-file","fs:allow-write-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":["$APP/*","$DESKTOP/*"]},"shell:allow-open","fs:default","shell:default"]}}
37 changes: 37 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate dotenv_codegen;

//Tauri
use tauri::Manager;
use tauri_plugin_updater::UpdaterExt;

use std::{sync::mpsc, thread};
// Ennesults
Expand Down Expand Up @@ -46,6 +47,18 @@ async fn main() {
crate::bot::api::delete_insult,
])
.setup(|app| {
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
match update(handle).await {
Err(err) => {
println!("Failed to update app! {}", err);
}
Ok(()) => {
println!("App has been updated successfully!")
}
}
});

println!("Setting up bot!");
let bot_info =
read_json_file::<BotInfo>(app.handle(), "bot_info.json").unwrap_or_default();
Expand Down Expand Up @@ -74,3 +87,27 @@ async fn main() {
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
if let Some(update) = app.updater()?.check().await? {
let mut downloaded = 0;

// alternatively we could also call update.download() and update.install() separately
update
.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
println!("downloaded {downloaded} from {content_length:?}");
},
|| {
println!("download finished");
},
)
.await?;

println!("update installed");
app.restart();
}

Ok(())
}
7 changes: 5 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"productName": "ennesults",
"mainBinaryName": "ennesults-rs",
"version": "0.2.0",
"version": "0.2.1",
"identifier": "com.christianpayne.ennesults",
"plugins": {
"updater": {
Expand All @@ -37,7 +37,10 @@
}
],
"security": {
"csp": null
"csp": null,
"capabilities": [
"desktop", "migrated"
]
}
}
}

0 comments on commit c6af5a2

Please sign in to comment.