Skip to content

Commit 4281edf

Browse files
committed
Tauri v2 fixes, Restart App fix
1 parent 292d5be commit 4281edf

8 files changed

Lines changed: 57 additions & 686 deletions

File tree

src-tauri/gen/schemas/acl-manifests.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src-tauri/gen/schemas/desktop-schema.json

Lines changed: 0 additions & 330 deletions
Large diffs are not rendered by default.

src-tauri/gen/schemas/windows-schema.json

Lines changed: 0 additions & 330 deletions
Large diffs are not rendered by default.

src-tauri/src/commands.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@ pub fn hide_window(app: AppHandle) -> Result<(), String> {
3232
pub async fn restart_app(app: AppHandle) -> Result<(), String> {
3333
#[cfg(debug_assertions)]
3434
{
35-
// Only allow restart in debug mode
36-
app.restart();
37-
// This line is unreachable but needed for type checking
38-
#[allow(unreachable_code)]
35+
// In development mode, reload all windows instead of restarting the entire process
36+
// This preserves the CLI dev server
37+
println!("Reloading application (dev mode)...");
38+
for (_label, window) in app.webview_windows() {
39+
let _ = window.eval("window.location.reload()");
40+
}
3941
Ok(())
4042
}
4143
#[cfg(not(debug_assertions))]
4244
{
43-
Err("Restart is only available in development mode".to_string())
45+
// In production mode, actually restart the application
46+
println!("Restarting application (production mode)...");
47+
app.restart();
48+
// This line is unreachable but needed for type checking
49+
#[allow(unreachable_code)]
50+
Ok(())
4451
}
4552
}

src-tauri/src/features.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,22 @@ macro_rules! feature_enabled {
104104
/// Tauri command to get enabled features at runtime
105105
#[tauri::command]
106106
pub fn get_enabled_features() -> Vec<&'static str> {
107-
let mut v = Vec::new();
107+
let mut features = Vec::new();
108+
108109
#[cfg(feature = "notifications")]
109-
v.push("notifications");
110+
features.push("notifications");
111+
110112
#[cfg(feature = "deep-links")]
111-
v.push("deep-links");
113+
features.push("deep-links");
114+
112115
#[cfg(feature = "clipboard")]
113-
v.push("clipboard");
116+
features.push("clipboard");
117+
114118
#[cfg(feature = "system-tray")]
115-
v.push("system-tray");
119+
features.push("system-tray");
120+
116121
#[cfg(feature = "window-manager")]
117-
v.push("window-manager");
118-
v
122+
features.push("window-manager");
123+
124+
features
119125
}

src-tauri/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn main() {
4545
#[cfg(feature = "clipboard")]
4646
let builder = builder.plugin(tauri_plugin_clipboard_manager::init());
4747

48-
let mut app_builder = builder
48+
let app_builder = builder
4949
.invoke_handler(tauri::generate_handler![
5050
greet,
5151
show_window,
@@ -121,9 +121,7 @@ fn main() {
121121
]);
122122

123123
#[cfg(feature = "window-manager")]
124-
{
125-
app_builder = app_builder.manage(init_window_state());
126-
}
124+
let app_builder = app_builder.manage(init_window_state());
127125

128126
app_builder
129127
.setup(|app| {

src-tauri/src/menu.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn create_app_menu(app: &App) -> Result<Menu<tauri::Wry>> {
7777
"Developer",
7878
true,
7979
&[
80-
&MenuItem::with_id(app, "restart_app", "Restart App", true, Some("CmdOrCtrl+Shift+R"))?,
80+
&MenuItem::with_id(app, "restart_app", "Reload App (Dev)", true, Some("CmdOrCtrl+Shift+R"))?,
8181
&PredefinedMenuItem::separator(app)?,
8282
&MenuItem::with_id(app, "reload_all", "Reload All Windows", true, Some("CmdOrCtrl+Shift+F5"))?,
8383
],
@@ -98,7 +98,17 @@ pub fn handle_menu_event(app: &AppHandle, event: tauri::menu::MenuEvent) {
9898
"restart_app" => {
9999
#[cfg(debug_assertions)]
100100
{
101-
println!("Restarting application...");
101+
// In development mode, reload all windows instead of restarting the entire process
102+
// This preserves the CLI dev server
103+
println!("Reloading application (dev mode)...");
104+
for (_label, window) in app.webview_windows() {
105+
let _ = window.eval("window.location.reload()");
106+
}
107+
}
108+
#[cfg(not(debug_assertions))]
109+
{
110+
// In production mode, actually restart the application
111+
println!("Restarting application (production mode)...");
102112
app.restart();
103113
}
104114
}
@@ -117,12 +127,12 @@ pub fn handle_menu_event(app: &AppHandle, event: tauri::menu::MenuEvent) {
117127
}
118128
}
119129
"toggle_devtools" => {
130+
#[cfg(debug_assertions)]
120131
if let Some(window) = app.get_webview_window("main") {
121-
if window.is_devtools_open() {
122-
let _ = window.close_devtools();
123-
} else {
124-
let _ = window.open_devtools();
125-
}
132+
// In Tauri v2, devtools are handled differently
133+
// For now, we'll just focus the window
134+
let _ = window.set_focus();
135+
println!("DevTools toggle requested (not implemented in Tauri v2)");
126136
}
127137
}
128138
"about" => {

src-tauri/src/tray.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn create_tray_menu(app: &App) -> Result<Menu<tauri::Wry>> {
1616
&MenuItem::with_id(app, "about_tray", "About", true, None::<&str>)?,
1717
&MenuItem::with_id(app, "settings", "Settings", true, None::<&str>)?,
1818
&PredefinedMenuItem::separator(app)?,
19-
&MenuItem::with_id(app, "restart_app_tray", "Restart App", true, None::<&str>)?,
19+
&MenuItem::with_id(app, "restart_app_tray", "Reload App (Dev)", true, None::<&str>)?,
2020
&PredefinedMenuItem::separator(app)?,
2121
&PredefinedMenuItem::quit(app, Some("Quit"))?,
2222
],
@@ -71,7 +71,17 @@ pub fn handle_tray_menu_event(app: &AppHandle, event: tauri::menu::MenuEvent) {
7171
"restart_app_tray" => {
7272
#[cfg(debug_assertions)]
7373
{
74-
println!("Restarting application from tray...");
74+
// In development mode, reload all windows instead of restarting the entire process
75+
// This preserves the CLI dev server
76+
println!("Reloading application from tray (dev mode)...");
77+
for (_label, window) in app.webview_windows() {
78+
let _ = window.eval("window.location.reload()");
79+
}
80+
}
81+
#[cfg(not(debug_assertions))]
82+
{
83+
// In production mode, actually restart the application
84+
println!("Restarting application from tray (production mode)...");
7585
app.restart();
7686
}
7787
}

0 commit comments

Comments
 (0)