Skip to content

Commit 6157eb7

Browse files
committed
feat: add 'Check for updates' option to tray menu and improve update handling
1 parent e29f2fc commit 6157eb7

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

assets/css/settings.scss

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
$primary: #2E2D2B;
2-
$accent: #FEB453;
1+
$primary: #2e2d2b;
2+
$accent: #feb453;
33
$divider: #ffffff0d;
44

5-
$text: #E5DFD5;
6-
$text2: #ADA9A1;
7-
$mutedtext: #78756F;
5+
$text: #e5dfd5;
6+
$text2: #ada9a1;
7+
$mutedtext: #78756f;
88

99
.bg {
1010
width: 750px;
@@ -25,7 +25,7 @@ $mutedtext: #78756F;
2525
gap: 8px;
2626
align-items: center;
2727

28-
img{
28+
img {
2929
background-color: $divider;
3030
border-radius: 6px;
3131
padding: 8px 6px;
@@ -123,7 +123,7 @@ $mutedtext: #78756F;
123123
background-color: $divider;
124124
margin-left: 8px;
125125
margin-right: 4px;
126-
transition: all .2s;
126+
transition: all 0.2s;
127127
}
128128

129129
.actions {
@@ -134,16 +134,16 @@ $mutedtext: #78756F;
134134
gap: 8px;
135135
border-radius: 7px;
136136
background-color: transparent;
137-
transition: all .2s;
137+
transition: all 0.2s;
138138
cursor: pointer;
139139
}
140140

141141
.actions:hover {
142142
background-color: $divider;
143143
}
144144

145-
&:hover .actions:hover~.divider {
145+
&:hover .actions:hover ~ .divider {
146146
opacity: 0;
147147
}
148148
}
149-
}
149+
}

src-tauri/src/api/tray.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
2323
.build(app)?])
2424
.items(&[&MenuItemBuilder::with_id("show", "Show/Hide").build(app)?])
2525
.items(&[&MenuItemBuilder::with_id("keybind", "Change keybind").build(app)?])
26+
.items(&[&MenuItemBuilder::with_id("check_updates", "Check for updates").build(app)?])
2627
.items(&[&MenuItemBuilder::with_id("quit", "Quit").build(app)?])
2728
.build()?,
2829
)
@@ -48,6 +49,13 @@ pub fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
4849
let _ = _app.track_event("tray_keybind_change", None);
4950
window.emit("change_keybind", ()).unwrap();
5051
}
52+
"check_updates" => {
53+
let _ = _app.track_event("tray_check_updates", None);
54+
let app_handle = _app.app_handle().clone();
55+
tauri::async_runtime::spawn(async move {
56+
crate::api::updater::check_for_updates(app_handle, true).await;
57+
});
58+
}
5159
_ => (),
5260
})
5361
.icon(icon)

src-tauri/src/api/updater.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use tauri::Manager;
12
use tauri::{async_runtime, AppHandle};
23
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind};
34
use tauri_plugin_updater::UpdaterExt;
45

5-
pub async fn check_for_updates(app: AppHandle) {
6+
pub async fn check_for_updates(app: AppHandle, prompted: bool) {
67
println!("Checking for updates...");
78

89
let updater = app.updater().unwrap();
@@ -18,6 +19,10 @@ pub async fn check_for_updates(app: AppHandle) {
1819
"Would you like to install it now?",
1920
]);
2021

22+
let window = app.get_webview_window("main").unwrap();
23+
window.show().unwrap();
24+
window.set_focus().unwrap();
25+
2126
app.dialog()
2227
.message(msg)
2328
.title("Qopy Update Available")
@@ -31,7 +36,7 @@ pub async fn check_for_updates(app: AppHandle) {
3136
Ok(_) => {
3237
app.dialog()
3338
.message("Update installed successfully. The application needs to restart to apply the changes.")
34-
.title("Qopy Update Installed")
39+
.title("Qopy Needs to Restart")
3540
.buttons(MessageDialogButtons::OkCancelCustom(String::from("Restart"), String::from("Cancel")))
3641
.show(move |response| {
3742
if response {
@@ -50,9 +55,22 @@ pub async fn check_for_updates(app: AppHandle) {
5055
});
5156
});
5257
}
53-
Ok(None) => println!("No updates available."),
58+
Ok(None) => {
59+
println!("No updates available.");
60+
}
5461
Err(e) => {
55-
println!("Failed to check for updates: {:?}", e);
62+
if prompted {
63+
let window = app.get_webview_window("main").unwrap();
64+
window.show().unwrap();
65+
window.set_focus().unwrap();
66+
67+
app.dialog()
68+
.message("No updates available.")
69+
.title("Qopy Update Check")
70+
.show(|_| {});
71+
}
72+
73+
println!("No updates available. {}", e.to_string());
5674
}
5775
}
5876
}

src-tauri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() {
9696
let _ = app.track_event("app_started", None);
9797

9898
tauri::async_runtime::spawn(async move {
99-
api::updater::check_for_updates(app_handle).await;
99+
api::updater::check_for_updates(app_handle, false).await;
100100
});
101101

102102
Ok(())

0 commit comments

Comments
 (0)