onagre-launcher / onagre

A general purpose application launcher for X and wayland inspired by rofi/wofi and alfred
MIT License
536 stars 26 forks source link

feat: accept command as a cli parameter #68

Closed juanolon closed 8 months ago

juanolon commented 11 months ago

Hello, i have being trying to add a new parameter to onagre, so it can start right away with a plugin activated. for example: onagre "=" would start the calculator plugin. in this way, it would be possible to map eg. super+c to the calculator in i3 or sway.

As you may notice, the code is incomplete and with some extra debug prints. It is my first time programming rust. Anyway, I've got to add the parameter and initialize onagre with the given string. But the UI doesn't get updated. You will realize that I just update the state of onagre after initializing the struct (this may be not desired, as onagre need to be mutable for that). I've also tried a second approach, which sends an InputChange message to onagre directly after initialization instead of updating the state. Sadly, it doesn't work, because it seems that the channel to communicate to pop isn't yet initialized. this is the debug:

[2023-11-04T23:13:43Z DEBUG onagre::app::subscriptions::pop_launcher] Starting `pop-launcher` subscription
[2023-11-04T23:13:43Z DEBUG onagre::db] Got 2 database entries from for 'desktop-entries'
[2023-11-04T23:13:43Z DEBUG onagre::app::state] set_input got "=", prev modi: ""
[2023-11-04T23:13:43Z DEBUG onagre::app::state] terms: "="
[2023-11-04T23:13:43Z DEBUG onagre::app::state] plug split: None
[2023-11-04T23:13:43Z DEBUG onagre::app::state] got none plug split
[2023-11-04T23:13:43Z DEBUG onagre::app::state] State: mode=DesktopEntry, input==
thread 'main' panicked at src/app/mod.rs:583:47:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It would be really nice to get some help in this issue. Maybe there is even a better solution. Thanks

oknozor commented 11 months ago

Hey @juanolon thanks for the PR.

You probably need to change the default State implementation to do something like this:

impl State<'_> {
    fn with_mode() -> Self {
        State {
            selected: Selection::History(0),
            cache: Default::default(),
            pop_search: Default::default(),
            scroll: Default::default(),
            input_value: SearchInput {
                // Some arbitrary values here but this should come from the cli args
                mode: ActiveMode::Web {
                    modifier: "ddg".to_string(),
                },
                modifier_display: "ddg".to_string(),
                input_display: "toto".to_string(),
                pop_query: "ddg toto".to_string(),
            },
            exec_on_next_search: false,
            plugin_matchers: PluginConfigCache::default(),
        }
    }
}

This should be called on start instead of State::default to build the initial state. You could make this take an optional ActiveMode as parameter so it fallback to the default impl when the start mode is not provided.

Note that I have tested with web mode but this might require some tweaking to make onagre refresh the displayed entry on start if the plugin needs to display entry from pop-launcher backend.

juanolon commented 10 months ago

With the last commit, it is now possible to execute onagre in the following way: onagre "find " or onagre "=" Whenever a plugin match the given string, it will start directly with that plugin activated.

cocogitto-bot[bot] commented 10 months ago

:heavy_check_mark: 3590d3f...f5627ad - Conventional commits check succeeded.