Skip to content

Commit

Permalink
fix: handle better window position size with multiple monitors and sc…
Browse files Browse the repository at this point in the history
…alefactorchanged (#245)

* fix: handle better window position size with multiple monitors and scale factors

* fix: handle better window position size with multiple monitors and scale factors

* fix: handle better window position size with multiple monitors and scale factors

* fix: handle better window position size with multiple monitors and scale factors
  • Loading branch information
hcavarsan committed Jun 1, 2024
1 parent 75ce08b commit dc94acb
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ node_modules
target/*
target*/*
target*
frontend/dist/**
frontend/dist/*

4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@

<h2> Download latest release </h2>
<div align="left">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.3_universal.dmg">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.5_universal.dmg">
<img src="https://img.shields.io/badge/-macOS (Universal)-grey.svg?style=for-the-badge&logo=apple" alt="Download for macOS" />
</a>
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.3_arm64-setup.exe">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.5_arm64-setup.exe">
<img src="https://img.shields.io/badge/-Windows (ARM64)-grey.svg?style=for-the-badge&logo=windows" alt="Download for Windows ARM64" />
</a>
<br />
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.3_x64-setup.exe">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.5_x64-setup.exe">
<img src="https://img.shields.io/badge/-Windows (x64)-grey.svg?style=for-the-badge&logo=windows" alt="Download for Windows x64" />
</a>
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.3_x86-setup.exe">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.5_x86-setup.exe">
<img src="https://img.shields.io/badge/-Windows (x86)-grey.svg?style=for-the-badge&logo=windows" alt="Download for Windows x86" />
</a>
<br />
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.3_amd64.AppImage">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.5_amd64.AppImage">
<img src="https://img.shields.io/badge/-Linux (x64)-grey.svg?style=for-the-badge&logo=linux" alt="Download for Linux AMD64" />
</a>
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.3_aarch64.AppImage">
<a href="https://github.com/hcavarsan/kftray/releases/latest/download/kftray_0.11.5_aarch64.AppImage">
<img src="https://img.shields.io/badge/-Linux (ARM64)-grey.svg?style=for-the-badge&logo=linux" alt="Download for Linux AARCH64" />
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion crates/kftray-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kftray-server"
version = "0.11.3"
version = "0.11.5"
description = "KFtray Server is a Rust application that relays UDP/TCP traffic to an upstream server"
authors = [
"Henrique Cavarsan <hencavarsan@gmail.com>",
Expand Down
2 changes: 1 addition & 1 deletion crates/kftray-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kftray"
version = "0.11.3"
version = "0.11.5"
description = "A cross-platform system tray app for Kubernetes port-forward management"
authors = [
"Henrique Cavarsan <hencavarsan@gmail.com>",
Expand Down
11 changes: 8 additions & 3 deletions crates/kftray-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod remote_config;
mod tray;
mod window;

use std::sync::atomic::AtomicBool;

use tauri::{
GlobalShortcutManager,
Manager,
Expand All @@ -33,9 +35,10 @@ use crate::tray::{
handle_window_event,
};
use crate::window::toggle_window_visibility;
struct AppState {
is_moving: Arc<Mutex<bool>>,
runtime: Arc<Runtime>,
pub struct AppState {
pub is_moving: Arc<Mutex<bool>>,
pub is_plugin_moving: Arc<AtomicBool>,
pub runtime: Arc<Runtime>,
}

fn main() {
Expand All @@ -46,11 +49,13 @@ fn main() {
// configure tray menu
let system_tray = create_tray_menu();
let is_moving = Arc::new(Mutex::new(false));
let is_plugin_moving = Arc::new(AtomicBool::new(false));
let runtime = Arc::new(Runtime::new().expect("Failed to create a Tokio runtime"));
let app = tauri::Builder::default()
.manage(SaveDialogState::default())
.manage(AppState {
is_moving: is_moving.clone(),
is_plugin_moving: is_plugin_moving.clone(),
runtime: runtime.clone(),
})
.setup(move |app| {
Expand Down
6 changes: 3 additions & 3 deletions crates/kftray-tauri/src/models/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl Default for SaveDialogState {
}
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WindowPosition {
pub x: f64,
pub y: f64,
pub x: i32,
pub y: i32,
}
26 changes: 25 additions & 1 deletion crates/kftray-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use tokio::time::sleep;
use crate::kubeforward::port_forward;
use crate::models::window::SaveDialogState;
use crate::window::{
adjust_window_size_and_position,
reset_window_position,
save_window_position,
set_default_position,
set_window_position,
toggle_window_visibility,
};
Expand Down Expand Up @@ -70,6 +72,24 @@ pub fn create_tray_menu() -> SystemTray {
}

pub fn handle_window_event(event: GlobalWindowEvent) {
if let tauri::WindowEvent::ScaleFactorChanged {
scale_factor,
new_inner_size,
..
} = event.event()
{
let window = event.window();
adjust_window_size_and_position(window, *scale_factor, *new_inner_size);
if !window.is_visible().unwrap() || !window.is_focused().unwrap() {
set_default_position(window);
window.show().unwrap();
window.set_focus().unwrap();
}

return;
}

println!("event: {:?}", event.event());
let app_state = event.window().state::<AppState>();
let mut is_moving = app_state.is_moving.lock().unwrap();

Expand Down Expand Up @@ -119,7 +139,11 @@ pub fn handle_window_event(event: GlobalWindowEvent) {
{}
});

if !*is_moving {
if !*is_moving && !app_state.is_plugin_moving.load(Ordering::SeqCst) {
println!(
"is_plugin_moving: {}",
app_state.is_plugin_moving.load(Ordering::SeqCst)
);
*is_moving = true;
let app_handle = event.window().app_handle();

Expand Down
Loading

0 comments on commit dc94acb

Please sign in to comment.