Skip to content

Commit 1475c72

Browse files
FreddyFunkjackpot51
authored andcommitted
feat: add standalone run mode via 'just run' or 'cosmic-app-library run'
1 parent 900edfb commit 1475c72

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ build-release *args: (build-debug '--release' args)
3333
# Compiles release profile with vendored dependencies
3434
build-vendored *args: vendor-extract (build-release '--frozen --offline' args)
3535

36+
# Compiles and runs a standalone instance
37+
run *args: build-release
38+
{{bin-src}} run {{args}}
39+
3640
# Runs a clippy check
3741
check *args:
3842
cargo clippy --all-features {{args}} -- -W clippy::pedantic

src/app.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ pub enum ApplicationsTasks {
146146
Input { input: Option<String> },
147147
#[clap(about = "Close app-library if open")]
148148
Close,
149+
#[clap(about = "Run a standalone instance (not single-instance)")]
150+
Run,
149151
}
150152

151153
impl Display for ApplicationsTasks {
@@ -163,17 +165,22 @@ impl FromStr for ApplicationsTasks {
163165
}
164166

165167
pub fn run() -> cosmic::iced::Result {
166-
cosmic::app::run_single_instance::<CosmicAppLibrary>(
167-
Settings::default()
168-
.antialiasing(true)
169-
.client_decorations(true)
170-
.debug(false)
171-
.default_text_size(16.0)
172-
.scale_factor(1.0)
173-
.no_main_window(true)
174-
.exit_on_close(false),
175-
Args::parse(),
176-
)
168+
let args = Args::parse();
169+
let settings = Settings::default()
170+
.antialiasing(true)
171+
.client_decorations(true)
172+
.debug(false)
173+
.default_text_size(16.0)
174+
.scale_factor(1.0)
175+
.no_main_window(true)
176+
.exit_on_close(false);
177+
178+
// Use standalone run if requested, otherwise use single-instance
179+
if matches!(args.subcommand, Some(ApplicationsTasks::Run)) {
180+
cosmic::app::run::<CosmicAppLibrary>(settings, args)
181+
} else {
182+
cosmic::app::run_single_instance::<CosmicAppLibrary>(settings, args)
183+
}
177184
}
178185

179186
pub struct AppSource(PathSource);
@@ -387,6 +394,7 @@ impl CosmicAppLibrary {
387394

388395
#[derive(Clone, Debug)]
389396
enum Message {
397+
Activate,
390398
UpdateFocused(Option<widget::Id>),
391399
InputChanged(String),
392400
KeyboardNav(keyboard_nav::Action),
@@ -607,6 +615,9 @@ impl cosmic::Application for CosmicAppLibrary {
607615

608616
fn update(&mut self, message: Message) -> Task<Self::Message> {
609617
match message {
618+
Message::Activate => {
619+
return self.activate();
620+
}
610621
Message::UpdateFocused(id) => {
611622
self.focused_id = id;
612623
let i = self
@@ -1100,6 +1111,8 @@ impl cosmic::Application for CosmicAppLibrary {
11001111
Task::none()
11011112
}
11021113
ApplicationsTasks::Close => self.hide(),
1114+
// Run is handled at startup, not via D-Bus
1115+
ApplicationsTasks::Run => Task::none(),
11031116
}
11041117
}
11051118
_ => Task::none(),
@@ -1719,7 +1732,7 @@ impl cosmic::Application for CosmicAppLibrary {
17191732
&mut self.core
17201733
}
17211734

1722-
fn init(mut core: Core, _flags: Args) -> (Self, iced::Task<cosmic::Action<Self::Message>>) {
1735+
fn init(mut core: Core, flags: Args) -> (Self, iced::Task<cosmic::Action<Self::Message>>) {
17231736
core.set_keyboard_nav(false);
17241737
let helper = AppLibraryConfig::helper();
17251738

@@ -1757,6 +1770,13 @@ impl cosmic::Application for CosmicAppLibrary {
17571770
..Default::default()
17581771
};
17591772

1760-
(self_, Task::none())
1773+
// Auto-activate when running in standalone mode
1774+
let task = if matches!(flags.subcommand, Some(ApplicationsTasks::Run)) {
1775+
Task::done(cosmic::Action::App(Message::Activate))
1776+
} else {
1777+
Task::none()
1778+
};
1779+
1780+
(self_, task)
17611781
}
17621782
}

0 commit comments

Comments
 (0)