Skip to content

Commit

Permalink
refactor: allow apps to request to be treated as a daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Nov 13, 2024
1 parent 59a3175 commit 35b9453
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub trait Program: Sized {
default_text_size: settings.default_text_size,
antialiasing: settings.antialiasing,
exit_on_close_request: settings.exit_on_close_request,
is_daemon: settings.exit_on_close_request,
}
.into(),
renderer_settings,
Expand Down
5 changes: 5 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub struct Settings {

/// If set to true the application will exit when the main window is closed.
pub exit_on_close_request: bool,

/// Whether the application is a daemon
pub is_daemon: bool,
}

impl Default for Settings {
Expand All @@ -46,6 +49,7 @@ impl Default for Settings {
default_text_size: Pixels(14.0),
antialiasing: false,
exit_on_close_request: false,
is_daemon: false,
}
}
}
Expand All @@ -56,6 +60,7 @@ impl From<Settings> for iced_winit::Settings {
iced_winit::Settings {
id: settings.id,
fonts: settings.fonts,
is_daemon: settings.is_daemon,
}
}
}
2 changes: 1 addition & 1 deletion winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ where
};

let (program, task) = runtime.enter(|| P::new(flags));
let is_daemon = window_settings.is_none();
let is_daemon = window_settings.is_none() || settings.is_daemon;

let task = if let Some(window_settings) = window_settings {
let mut task = Some(task);
Expand Down
3 changes: 3 additions & 0 deletions winit/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ pub struct Settings {

/// The fonts to load on boot.
pub fonts: Vec<Cow<'static, [u8]>>,

/// Whether the application should exit when no windows are left
pub is_daemon: bool,
}

0 comments on commit 35b9453

Please sign in to comment.