Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 114 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ eframe = { version = "0.31.1", default-features = false, features = [

# plugins
async-trait = "0.1.89"
async-std = "1.12.0"
smol = "2"
async-channel = "2"
futures-lite = "2"

# reading index files
serde_json = "1.0.139"
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Centerpiece {
query: String,
active_entry_index: usize,
plugins: Vec<model::Plugin>,
plugin_channels: Vec<async_std::channel::Receiver<Message>>,
plugin_channels: Vec<async_channel::Receiver<Message>>,
}

impl eframe::App for Centerpiece {
Expand Down
2 changes: 1 addition & 1 deletion client/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct Plugin {
pub priority: u32,
pub title: String,
pub entries: Vec<Entry>,
pub app_channel_out: async_std::channel::Sender<PluginRequest>,
pub app_channel_out: async_channel::Sender<PluginRequest>,
}

#[derive(Debug, Clone, Ord, PartialOrd)]
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Plugin for ApplicationsPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
let command = entry.command.context(format!(
"Failed to unpack command while activating entry with id '{}'.",
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/brave/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Plugin for BookmarksPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
std::process::Command::new("brave")
.arg(&entry.id)
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/brave/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Plugin for HistoryPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
std::process::Command::new("brave")
.arg(&entry.id)
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/brave/progressive_web_apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Plugin for ProgressiveWebAppsPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
std::process::Command::new("brave")
.arg(format!("--app={}", entry.id))
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/firefox/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Plugin for BookmarksPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
std::process::Command::new("firefox")
.arg(&entry.id)
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/firefox/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Plugin for HistoryPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
std::process::Command::new("firefox")
.arg(&entry.id)
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/git_repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Plugin for GitRepositoriesPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
for command in self.settings.plugin.git_repositories.commands.clone() {
let parsed_command: Vec<String> = command
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/gitmoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl Plugin for GitmojiPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
std::process::Command::new("wl-copy")
.arg(&entry.id)
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/sway_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Plugin for SwayWindowsPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
self.sway
.run_command(format!("[con_id={}] focus", entry.id))
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Plugin for SystemPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
let command = entry.command.context(format!(
"Failed to unpack command while activating entry with id '{}'.",
Expand Down
60 changes: 31 additions & 29 deletions client/src/plugin/utils.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use anyhow::Context;
use async_std::stream::StreamExt;
use nucleo_matcher::{
Matcher, Utf32Str,
pattern::{Atom, AtomKind, CaseMatching, Normalization},
};
use std::cmp::Reverse;

pub fn spawn<PluginType: Plugin + std::marker::Send + 'static>()
-> async_std::channel::Receiver<crate::Message> {
let (plugin_channel_out, app_channel_in) = async_std::channel::bounded(100);

async_std::task::spawn(async {
let mut plugin = PluginType::new();

let main_loop_result = plugin.main(plugin_channel_out).await;
if let Err(error) = main_loop_result {
log::error!(
target: PluginType::id(),
"{:?}", error,
);
panic!();
}
-> async_channel::Receiver<crate::Message> {
let (plugin_channel_out, app_channel_in) = async_channel::bounded(100);

std::thread::spawn(move || {
smol::block_on(async {
let mut plugin = PluginType::new();

let main_loop_result = plugin.main(plugin_channel_out).await;
if let Err(error) = main_loop_result {
log::error!(
target: PluginType::id(),
"{:?}", error,
);
panic!();
}
});
});

return app_channel_in;
Expand Down Expand Up @@ -101,7 +102,7 @@ pub trait Plugin {

fn plugin(
&self,
app_channel_out: &mut async_std::channel::Sender<crate::model::PluginRequest>,
app_channel_out: &mut async_channel::Sender<crate::model::PluginRequest>,
) -> crate::model::Plugin {
crate::model::Plugin {
id: String::from(Self::id()),
Expand All @@ -114,11 +115,11 @@ pub trait Plugin {

async fn main(
&mut self,
mut plugin_channel_out: async_std::channel::Sender<crate::Message>,
mut plugin_channel_out: async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
self.update_entries()?;

let (mut app_channel_out, mut plugin_channel_in) = async_std::channel::bounded(100);
let (mut app_channel_out, mut plugin_channel_in) = async_channel::bounded(100);
self.register_plugin(&mut plugin_channel_out, &mut app_channel_out)?;
let mut last_query = String::from("");

Expand All @@ -134,8 +135,8 @@ pub trait Plugin {

fn register_plugin(
&mut self,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
app_channel_out: &mut async_std::channel::Sender<crate::model::PluginRequest>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
app_channel_out: &mut async_channel::Sender<crate::model::PluginRequest>,
) -> anyhow::Result<()> {
plugin_channel_out
.send_blocking(crate::Message::RegisterPlugin(self.plugin(app_channel_out)))
Expand All @@ -146,18 +147,19 @@ pub trait Plugin {

async fn update(
&mut self,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_in: &mut async_std::channel::Receiver<crate::model::PluginRequest>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
plugin_channel_in: &mut async_channel::Receiver<crate::model::PluginRequest>,
last_query: &mut String,
) -> anyhow::Result<()> {
let plugin_request_future = plugin_channel_in.next();
let plugin_request_option = match Self::update_timeout() {
Some(update_timeout) => {
async_std::future::timeout(update_timeout, plugin_request_future)
.await
.unwrap_or(Some(crate::model::PluginRequest::Timeout))
futures_lite::future::or(async { plugin_channel_in.recv().await.ok() }, async {
smol::Timer::after(update_timeout).await;
Some(crate::model::PluginRequest::Timeout)
})
.await
}
None => plugin_request_future.await,
None => plugin_channel_in.recv().await.ok(),
};
if plugin_request_option.is_none() {
return Ok(());
Expand Down Expand Up @@ -190,7 +192,7 @@ pub trait Plugin {
fn search(
&mut self,
query: &str,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
let filtered_entries = fuzzy_match(query, self.entries());

Expand All @@ -210,7 +212,7 @@ pub trait Plugin {
fn activate(
&mut self,
_entry: crate::model::Entry,
_plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
_plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/plugin/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Plugin for WifiPlugin {
fn activate(
&mut self,
entry: crate::model::Entry,
plugin_channel_out: &mut async_std::channel::Sender<crate::Message>,
plugin_channel_out: &mut async_channel::Sender<crate::Message>,
) -> anyhow::Result<()> {
let command = entry.command.context(format!(
"Failed to unpack command while activating entry with id '{}'.",
Expand Down