Skip to content

Commit 0e55497

Browse files
committed
fix/change: show window when start_minimized is true and the user started the app manually
1 parent a44b42f commit 0e55497

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

RustApp/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ pub struct Args {
177177
default_value_t = false
178178
)]
179179
pub show_supported_audio_config: bool,
180+
181+
#[arg(long, hide = true, default_value_t = false)]
182+
pub launched_automatically: bool,
180183
}
181184

182185
#[derive(

RustApp/src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use ui::app::run_ui;
1313
use utils::{APP, ORG, QUALIFIER};
1414
use zconf::ConfigManager;
1515

16+
use crate::ui::app::Flags;
17+
1618
#[macro_use]
1719
extern crate log;
1820

@@ -147,9 +149,13 @@ fn main() {
147149
});
148150

149151
localize::localize();
150-
run_ui(
152+
153+
let flags = Flags {
151154
config,
152-
config_file_path.to_string_lossy().to_string(),
153-
log_file_path.to_string_lossy().to_string(),
154-
)
155+
config_path: config_file_path.to_string_lossy().to_string(),
156+
log_path: log_file_path.to_string_lossy().to_string(),
157+
launched_automatically: args.launched_automatically,
158+
};
159+
160+
run_ui(flags)
155161
}

RustApp/src/start_at_login.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ mod windows {
1919
fn create_shortcut(lnk: &Path) -> anyhow::Result<()> {
2020
let target = env::current_exe()?;
2121

22-
mslnk::ShellLink::new(target)?.create_lnk(lnk)?;
22+
let mut shell_link = mslnk::ShellLink::new(target)?;
23+
shell_link.set_name(Some(String::from("AndroidMic")));
24+
shell_link.set_arguments(Some(String::from("--launched-automatically")));
25+
shell_link.create_lnk(lnk)?;
2326

2427
Ok(())
2528
}

RustApp/src/ui/app.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@ use crate::{
4141
};
4242
use zconf::ConfigManager;
4343

44-
pub fn run_ui(config: ConfigManager<Config>, config_path: String, log_path: String) {
44+
pub fn run_ui(flags: Flags) {
4545
let settings = Settings::default()
4646
.no_main_window(true)
47-
.theme(to_cosmic_theme(&config.data().theme));
48-
49-
let flags = Flags {
50-
config,
51-
config_path,
52-
log_path,
53-
};
47+
.theme(to_cosmic_theme(&flags.config.data().theme));
5448

5549
cosmic::app::run::<AppState>(settings, flags).unwrap();
5650
}
@@ -137,6 +131,7 @@ pub struct AppState {
137131
pub system_tray: Option<SystemTray>,
138132
pub system_tray_stream: Option<SystemTrayStream>,
139133
has_shown_minimize_notification: bool,
134+
launched_automatically: bool,
140135
}
141136

142137
pub struct CustomWindow {
@@ -274,9 +269,10 @@ impl AppState {
274269
}
275270

276271
pub struct Flags {
277-
config: ConfigManager<Config>,
278-
config_path: String,
279-
log_path: String,
272+
pub config: ConfigManager<Config>,
273+
pub config_path: String,
274+
pub log_path: String,
275+
pub launched_automatically: bool,
280276
}
281277

282278
// used because the markdown parsing only detect https links
@@ -386,6 +382,7 @@ impl Application for AppState {
386382
system_tray,
387383
system_tray_stream,
388384
has_shown_minimize_notification: false,
385+
launched_automatically: flags.launched_automatically,
389386
};
390387

391388
commands.push(
@@ -403,7 +400,7 @@ impl Application for AppState {
403400
info!("config path: {}", flags.config_path);
404401
info!("log path: {}", flags.log_path);
405402

406-
if !app.config.data().start_minimized {
403+
if !flags.launched_automatically || !app.config.data().start_minimized {
407404
commands.push(app.open_main_window());
408405
}
409406

@@ -719,7 +716,7 @@ impl Application for AppState {
719716
self.about_window = None;
720717
}
721718

722-
if !self.config.data().start_minimized && !self.has_shown_minimize_notification {
719+
if !self.launched_automatically && !self.has_shown_minimize_notification {
723720
let _ = Notification::new()
724721
.summary("AndroidMic")
725722
.body(&fl!("minimized_to_tray"))

0 commit comments

Comments
 (0)