mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +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-cli = "2.0.0-beta"
|
||||||
tauri-plugin-notification = "2.0.0-beta"
|
tauri-plugin-notification = "2.0.0-beta"
|
||||||
tauri-plugin-log = "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"
|
tauri-cli = "2.0.0-beta.21"
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ mod window;
|
||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
use portmaster::PortmasterExt;
|
use portmaster::PortmasterExt;
|
||||||
|
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
|
||||||
use traymenu::setup_tray_menu;
|
use traymenu::setup_tray_menu;
|
||||||
use window::{close_splash_window, create_main_window};
|
use window::{close_splash_window, create_main_window};
|
||||||
|
|
||||||
|
@ -125,6 +126,8 @@ fn main() {
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
// OS Version and Architecture support
|
// OS Version and Architecture support
|
||||||
.plugin(tauri_plugin_os::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
|
// Initialize save windows state plugin.
|
||||||
|
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||||
// Single instance guard
|
// Single instance guard
|
||||||
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
|
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
|
||||||
let _ = app.emit("single-instance", Payload { args: 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 crate::service::ServiceManager;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::sync::atomic::Ordering;
|
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>;
|
pub type Result = std::result::Result<String, String>;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ use std::{
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use serde;
|
use serde;
|
||||||
use std::sync::Mutex;
|
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/";
|
const PORTMASTER_BASE_URL: &'static str = "http://127.0.0.1:817/api/v1/";
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ use tauri::{
|
||||||
tray::{TrayIcon, TrayIconBuilder},
|
tray::{TrayIcon, TrayIconBuilder},
|
||||||
Wry,
|
Wry,
|
||||||
};
|
};
|
||||||
|
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
portapi::{
|
portapi::{
|
||||||
|
@ -40,7 +41,6 @@ lazy_static! {
|
||||||
const PM_TRAY_ICON_ID: &'static str = "pm_icon";
|
const PM_TRAY_ICON_ID: &'static str = "pm_icon";
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
//
|
|
||||||
const BLUE_ICON: &'static [u8] = include_bytes!("../../../../assets/data/icons/pm_light_blue.ico");
|
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 RED_ICON: &'static [u8] = include_bytes!("../../../../assets/data/icons/pm_light_red.ico");
|
||||||
const YELLOW_ICON: &'static [u8] =
|
const YELLOW_ICON: &'static [u8] =
|
||||||
|
@ -395,7 +395,11 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
||||||
};
|
};
|
||||||
debug!("Shutdown request received: {:?}", msg);
|
debug!("Shutdown request received: {:?}", msg);
|
||||||
match 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);
|
return Ok(info.0);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(
|
dbg!(
|
||||||
"{}: failed to get icon: {}",
|
"{}: failed to get icon: {}",
|
||||||
info.0.icon_name,
|
info.0.icon_name,
|
||||||
err.to_string()
|
err.to_string()
|
||||||
|
@ -409,7 +409,7 @@ fn get_icon_as_png_dataurl(name: &str, size: i8) -> Result<(String, String)> {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
if icon_info.is_null() {
|
if icon_info.is_null() {
|
||||||
error!("failed to lookup icon {}", name);
|
dbg!("failed to lookup icon {}", name);
|
||||||
|
|
||||||
continue;
|
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()) {
|
match read_and_convert_pixbuf(filename.clone()) {
|
||||||
Ok(pb) => return Ok((filename, pb)),
|
Ok(pb) => return Ok((filename, pb)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("failed to load icon from {}: {}", filename, err.to_string());
|
dbg!("failed to load icon from {}: {}", filename, err.to_string());
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue