Skip to content

Commit

Permalink
feat: open dashboard window
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyL2 committed Jun 5, 2024
1 parent 297dfb2 commit 80f2d9a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/features/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tauri::{

use crate::commands::exit_app;

use super::window::{show_window, WindowLabel};
use super::window::{show_dashboard, WindowLabel};

#[derive(EnumString, AsRefStr, Display, PartialEq, Debug)]
enum MenuItemId {
Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn on_system_tray_event(app_handle: &AppHandle, event: SystemTrayEvent) {
match event {
SystemTrayEvent::MenuItemClick { id, .. } => match MenuItemId::from_str(id.as_str()) {
Ok(MenuItemId::OpenDashboard) => {
let _ = show_window(app_handle, WindowLabel::Dashboard);
let _ = show_dashboard(app_handle);
}
Ok(MenuItemId::Restart) => api::process::restart(&app_handle.env()),
Ok(MenuItemId::Quit) => exit_app(app_handle.clone()),
Expand Down
21 changes: 16 additions & 5 deletions src-tauri/src/features/window.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
use anyhow::Result;
use strum::{AsRefStr, Display, EnumString};
use tauri::{AppHandle, Manager};
use tauri::{AppHandle, Manager, WindowBuilder, WindowUrl};

#[derive(EnumString, AsRefStr, Display, PartialEq, Debug)]
#[strum(serialize_all = "PascalCase")]
pub enum WindowLabel {
Dashboard,
}

pub fn show_window(app_handle: &AppHandle, win_label: WindowLabel) -> Result<()> {
if let Some(window) = app_handle.get_window(win_label.as_ref()) {
pub fn show_dashboard(app_handle: &AppHandle) -> Result<()> {
let window_label = WindowLabel::Dashboard.as_ref();

if let Some(window) = app_handle.get_window(window_label) {
window
.show()
.and_then(|_| window.unminimize())
.and_then(|_| window.set_focus())?;
.and_then(|_| window.set_focus())?
}

Ok(())
let window = WindowBuilder::new(
app_handle,
window_label,
WindowUrl::App("index.html".into()),
)
.title(window_label)
.min_inner_size(600.0, 520.0)
.build()?;

Ok(window.set_focus()?)
}
15 changes: 11 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use features::tray::on_system_tray_event;
use tauri::SystemTray;
use tauri::{RunEvent, SystemTray};

mod commands;
mod features;
Expand Down Expand Up @@ -34,13 +34,20 @@ fn main() {

let context = tauri::generate_context!();

tauri::Builder::default()
let app = tauri::Builder::default()
.plugin(invoke_handler)
.plugin(tauri_plugin_single_instance::init(|_, _, _| {}))
.plugin(tauri_plugin_store::Builder::default().build())
.system_tray(SystemTray::new())
.on_system_tray_event(on_system_tray_event)
.setup(|app| Ok(setup::resolve_setup(app)?))
.run(context)
.expect("error while running tauri application");
.build(context)
.expect("error while building tauri application");

app.run(|_app_handle, event| match event {
RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
}
_ => {}
})
}
7 changes: 2 additions & 5 deletions src-tauri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use anyhow::Result;
use tauri::{App, Manager};

use crate::{
features::{
tray::create_tray_menu,
window::{show_window, WindowLabel},
},
features::{tray::create_tray_menu, window::show_dashboard},
keyecho::{run, KeySoundpack},
};

Expand All @@ -27,7 +24,7 @@ pub fn resolve_setup(app: &mut App) -> Result<()> {
let soundpack = KeySoundpack::try_load(app_handle)?;

if soundpack.current_sound().is_none() {
show_window(&app.app_handle(), WindowLabel::Dashboard)?;
show_dashboard(&app.app_handle())?;
}

let soundpack = Arc::new(Mutex::new(soundpack));
Expand Down

0 comments on commit 80f2d9a

Please sign in to comment.