feat(opt): add --with-plugin flag to daemon command

This commit is contained in:
Byson94
2025-10-14 19:58:46 +05:30
parent 4974df29d6
commit 18832c2956
4 changed files with 39 additions and 24 deletions

View File

@@ -11,10 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- `onkeypress` property to eventbox.
- `onkeyrelease` property to eventbox.
- Selection of dash as shell if it installed.
- `--with-plugin` flag for `daemon` command.
### Fixed
- Old widget creeping into new ones after hot reload.
- Ewwii defaulting to default gtk4 theme. #9
## [0.3.0-beta] - 2025-10-11

View File

@@ -148,7 +148,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, ewwii_binary_name: String) -> Result<
let should_restart = match &opts.action {
opts::Action::ShellCompletions { .. } => unreachable!(),
opts::Action::Daemon => opts.restart,
opts::Action::Daemon { .. } => opts.restart,
opts::Action::WithServer(action) => opts.restart && action.can_start_daemon(),
opts::Action::ClientOnly(_) => false,
};
@@ -168,11 +168,11 @@ fn run<B: DisplayBackend>(opts: opts::Opt, ewwii_binary_name: String) -> Result<
}
// make sure that there isn't already a Ewwii daemon running.
opts::Action::Daemon if check_server_running(paths.get_ipc_socket_file()) => {
opts::Action::Daemon {..} if check_server_running(paths.get_ipc_socket_file()) => {
eprintln!("Ewwii server already running.");
true
}
opts::Action::Daemon => {
opts::Action::Daemon { with_plugin } => {
log::info!("Initializing Ewwii server. ({})", paths.get_ipc_socket_file().display());
let _ = std::fs::remove_file(paths.get_ipc_socket_file());
@@ -183,7 +183,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, ewwii_binary_name: String) -> Result<
);
}
let fork_result =
server::initialize_server::<B>(paths.clone(), None, !opts.no_daemonize)?;
server::initialize_server::<B>(paths.clone(), None, !opts.no_daemonize, with_plugin)?;
opts.no_daemonize || fork_result == ForkResult::Parent
}
@@ -223,7 +223,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, ewwii_binary_name: String) -> Result<
let (command, response_recv) = action.into_daemon_command();
// start the daemon and give it the command
let fork_result =
server::initialize_server::<B>(paths.clone(), Some(command), true)?;
server::initialize_server::<B>(paths.clone(), Some(command), true, None)?;
let is_parent = fork_result == ForkResult::Parent;
if let (Some(recv), true) = (response_recv, is_parent) {
listen_for_daemon_response(recv);

View File

@@ -67,7 +67,10 @@ pub enum Action {
/// Start the Ewwii daemon.
#[command(name = "daemon", alias = "d")]
Daemon,
Daemon {
#[arg(long)]
with_plugin: Option<String>
},
#[command(flatten)]
ClientOnly(ActionClientOnly),

View File

@@ -22,6 +22,7 @@ pub fn initialize_server<B: DisplayBackend>(
paths: EwwiiPaths,
action: Option<DaemonCommand>,
should_daemonize: bool,
ewwii_plugin_path: Option<String>
) -> Result<ForkResult> {
let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel();
@@ -36,23 +37,6 @@ pub fn initialize_server<B: DisplayBackend>(
let config_parser =
Rc::new(RefCell::new(rhai_impl::parser::ParseConfig::new(Some(pl_handler_store.clone()))));
let mut config_parser_mut = config_parser.borrow_mut();
let read_config = config::read_from_ewwii_paths(&paths, &mut *config_parser_mut);
// free the temporary parser borrow
drop(config_parser_mut);
let ewwii_config = match read_config {
Ok(config) => config,
Err(err) => {
error_handling_ctx::print_error(err);
config::EwwiiConfig::default()
// TODO: Maybe do something so that we can exit if user wants.
// std::process::exit(1);
}
};
cleanup_log_dir(paths.get_log_dir())?;
@@ -92,7 +76,7 @@ pub fn initialize_server<B: DisplayBackend>(
let main_loop = gtk4::glib::MainLoop::new(None, false);
let mut app: App<B> = app::App {
ewwii_config,
ewwii_config: config::EwwiiConfig::default(),
open_windows: HashMap::new(),
failed_windows: HashSet::new(),
instance_id_to_args: HashMap::new(),
@@ -108,6 +92,31 @@ pub fn initialize_server<B: DisplayBackend>(
phantom: PhantomData,
};
// start up plugins
if let Some(ewwii_plugin) = ewwii_plugin_path {
if let Err(e) = app.set_ewwii_plugin(ewwii_plugin) {
error_handling_ctx::print_error(e);
}
}
let mut config_parser_mut = app.config_parser.borrow_mut();
let read_config = config::read_from_ewwii_paths(&app.paths, &mut *config_parser_mut);
// free the temporary parser borrow
drop(config_parser_mut);
match read_config {
Ok(new_config) => {
app.ewwii_config = new_config;
}
Err(err) => {
error_handling_ctx::print_error(err);
// TODO: Maybe do something so that we can exit if user wants.
// std::process::exit(1);
}
};
if let Some(display) = gtk4::gdk::Display::default() {
gtk4::style_context_add_provider_for_display(&display, &app.css_provider, 900);
}