mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
[desktop] tauri seve window size/position on exit
This commit is contained in:
parent
c3d787e3ce
commit
674787df87
6 changed files with 15 additions and 7 deletions
|
@ -25,6 +25,7 @@ tauri-plugin-single-instance = "2.0.0-beta"
|
|||
tauri-plugin-cli = "2.0.0-beta"
|
||||
tauri-plugin-notification = "2.0.0-beta"
|
||||
tauri-plugin-log = "2.0.0-beta"
|
||||
tauri-plugin-window-state = "2.0.0-beta.11"
|
||||
|
||||
tauri-cli = "2.0.0-beta.21"
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ mod window;
|
|||
|
||||
use log::{debug, error, info};
|
||||
use portmaster::PortmasterExt;
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
|
||||
use traymenu::setup_tray_menu;
|
||||
use window::{close_splash_window, create_main_window};
|
||||
|
||||
|
@ -125,6 +126,8 @@ fn main() {
|
|||
.plugin(tauri_plugin_dialog::init())
|
||||
// OS Version and Architecture support
|
||||
.plugin(tauri_plugin_os::init())
|
||||
// Initialize save windows state plugin.
|
||||
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||
// Single instance guard
|
||||
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
|
||||
let _ = app.emit("single-instance", Payload { args: argv, cwd });
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::service::get_service_manager;
|
|||
use crate::service::ServiceManager;
|
||||
use log::debug;
|
||||
use std::sync::atomic::Ordering;
|
||||
use tauri::{Manager, Runtime, State, Window};
|
||||
use tauri::{Emitter, Runtime, State, Window};
|
||||
|
||||
pub type Result = std::result::Result<String, String>;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ use std::{
|
|||
use log::{debug, error};
|
||||
use serde;
|
||||
use std::sync::Mutex;
|
||||
use tauri::{AppHandle, Manager, Runtime};
|
||||
use tauri::{AppHandle, Emitter, Manager, Runtime};
|
||||
|
||||
const PORTMASTER_BASE_URL: &'static str = "http://127.0.0.1:817/api/v1/";
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use tauri::{
|
|||
tray::{TrayIcon, TrayIconBuilder},
|
||||
Wry,
|
||||
};
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
|
||||
use crate::{
|
||||
portapi::{
|
||||
|
@ -40,7 +41,6 @@ lazy_static! {
|
|||
const PM_TRAY_ICON_ID: &'static str = "pm_icon";
|
||||
|
||||
// Icons
|
||||
//
|
||||
const BLUE_ICON: &'static [u8] = include_bytes!("../../../../assets/data/icons/pm_light_blue.ico");
|
||||
const RED_ICON: &'static [u8] = include_bytes!("../../../../assets/data/icons/pm_light_red.ico");
|
||||
const YELLOW_ICON: &'static [u8] =
|
||||
|
@ -395,7 +395,11 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
|||
};
|
||||
debug!("Shutdown request received: {:?}", msg);
|
||||
match msg {
|
||||
Response::Ok(_, _) | Response::New(_, _) | Response::Update(_, _) => app.exit(0),
|
||||
Response::Ok(_, _) | Response::New(_, _) | Response::Update(_, _) => {
|
||||
if let Err(err) = app.save_window_state(StateFlags::SIZE | StateFlags::POSITION) {
|
||||
error!("failed to save window state: {}", err);
|
||||
}
|
||||
app.exit(0)},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ pub fn get_app_info(process_info: ProcessInfo) -> Result<AppInfo> {
|
|||
return Ok(info.0);
|
||||
}
|
||||
Err(err) => {
|
||||
error!(
|
||||
dbg!(
|
||||
"{}: failed to get icon: {}",
|
||||
info.0.icon_name,
|
||||
err.to_string()
|
||||
|
@ -409,7 +409,7 @@ fn get_icon_as_png_dataurl(name: &str, size: i8) -> Result<(String, String)> {
|
|||
0,
|
||||
);
|
||||
if icon_info.is_null() {
|
||||
error!("failed to lookup icon {}", name);
|
||||
dbg!("failed to lookup icon {}", name);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ fn get_icon_as_png_dataurl(name: &str, size: i8) -> Result<(String, String)> {
|
|||
match read_and_convert_pixbuf(filename.clone()) {
|
||||
Ok(pb) => return Ok((filename, pb)),
|
||||
Err(err) => {
|
||||
error!("failed to load icon from {}: {}", filename, err.to_string());
|
||||
dbg!("failed to load icon from {}: {}", filename, err.to_string());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue