feat(tray): Added tray icon left-click event handling

- Implemented the function of displaying and focusing the main window when the tray icon is left-clicked
- Added handling logic for tray icon events
- Added Run Dev Server runtime configuration file
- Added Run spary Cargo command runtime configuration file
This commit is contained in:
2025-11-11 15:12:32 +08:00
parent 18ca4fd675
commit 8eaac4df96
3 changed files with 52 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Dev Server" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>

20
.run/Run spary.run.xml Normal file
View File

@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run spary" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="buildProfileId" value="dev" />
<option name="command" value="run --package spary --bin spary" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -1,8 +1,7 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
use tauri::Manager;
use crate::spary::spary_switch;
use tauri::menu::{Menu, MenuItem};
use tauri::tray::TrayIconBuilder;
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
use tauri_plugin_sql::{Migration, MigrationKind};
mod spary;
@@ -52,6 +51,24 @@ pub fn run() {
app.exit(0);
}
})
//Linux: Unsupported. The event is not emitted even though the icon is shown and will still show a context menu on right click.
.on_tray_icon_event(|tray, event| match event {
TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} => {
let app = tray.app_handle();
if let Some(window) = app.get_webview_window("main") {
let _ = window.unminimize();
let _ = window.show();
let _ = window.set_focus();
}
}
_ => {
println!("unhandled event {event:?}");
}
})
.build(app)?;
tray.set_menu(Some(menu))?;
Ok(())