When launching an app on Windows Tauri v2, the console window opens, but the app itself immediately closes, and the app itself disappears into the background. The same thing happens when refreshing the app page.
The application uses an "updater" (only by user action), deeplink, single-instance
set windows_subsystem in main.rs: #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
I compiled a binary file with debug, opened the console, and there were no errors or warnings.
This doesn't happen in development or debug mode, only after building in production with "npm run tauri build"
lib.rs:
pub fn handle_single_instance(app: &AppHandle, argv: Vec<String>, _cwd: String) {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
if argv.len() > 1 {
if let Some(raw) = argv.get(1) {
if let Ok(url) = Url::parse(raw) {
if let Ok(Some((action, value))) = handle_deep_link(&url) {
match action.as_str() {
"auth" => {
let _ = app.emit("auth:success", value);
}
"connect" => {
let _ = app.emit("plugin:connect", value);
}
_ => {}
}
}
}
}
}
}
fn handle_exit_event(_app_handle: &AppHandle, event: RunEvent) {
match event {
RunEvent::ExitRequested { .. } | RunEvent::Exit => {
let _ = stop_engine();
}
_ => {}
}
}
fn handle_setup(_app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
use tauri_plugin_deep_link::DeepLinkExt;
let _ = _app.deep_link().register_all();
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_single_instance::init(handle_single_instance))
.plugin(tauri_plugin_deep_link::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_opener::init())
.setup(handle_setup)
.invoke_handler(tauri::generate_handler![
get_config_data,
save_config,
run_engine,
stop_engine,
engine_status,
engine_install,
engine_is_installed,
has_access_token,
get_access_token,
get_profile,
get_news,
upgrade_manager,
get_installed_plugins,
get_marketplace_plugins,
get_plugin_data,
install_plugin,
get_client_id,
])
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(handle_exit_event);
}
main.rs:
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
raya_manager_lib::run()
}
capabilities/default.json:
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"core:window:default",
"core:window:allow-close",
"core:window:allow-minimize",
"core:window:allow-maximize",
"core:window:allow-toggle-maximize",
"core:window:allow-start-dragging",
"core:webview:allow-create-webview-window",
"opener:default",
"dialog:default",
"store:default",
"updater:default",
"deep-link:default"
]
}
To filter data in my app by OS, version and architecture I used os_info::get() this is what calls the console, now I use the plugin https://v2.tauri.app/plugin/os-info/ and everything is fine