diff --git a/Cargo.lock b/Cargo.lock index ee68017..3328e86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,17 +62,6 @@ dependencies = [ "slab", ] -[[package]] -name = "async-fs" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2" -dependencies = [ - "async-lock", - "blocking", - "futures-lite", -] - [[package]] name = "async-io" version = "1.6.0" @@ -101,17 +90,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-net" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5373304df79b9b4395068fb080369ec7178608827306ce4d081cba51cac551df" -dependencies = [ - "async-io", - "blocking", - "futures-lite", -] - [[package]] name = "async-oneshot" version = "0.5.0" @@ -131,23 +109,6 @@ dependencies = [ "libc", ] -[[package]] -name = "async-process" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83137067e3a2a6a06d67168e49e68a0957d215410473a740cea95a2425c0b7c6" -dependencies = [ - "async-io", - "blocking", - "cfg-if", - "event-listener", - "futures-lite", - "libc", - "once_cell", - "signal-hook", - "winapi", -] - [[package]] name = "async-recursion" version = "0.3.2" @@ -200,12 +161,6 @@ dependencies = [ "system-deps", ] -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "autocfg" version = "1.1.0" @@ -230,20 +185,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "blocking" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] - [[package]] name = "bumpalo" version = "3.9.1" @@ -784,7 +725,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.10.2+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -1171,6 +1112,29 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "mio" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + [[package]] name = "nanorand" version = "0.7.0" @@ -1203,6 +1167,15 @@ dependencies = [ "memoffset", ] +[[package]] +name = "ntapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +dependencies = [ + "winapi", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -1404,13 +1377,14 @@ dependencies = [ name = "pop-launcher" version = "1.1.1" dependencies = [ - "blocking", "const_format", "dirs 4.0.0", "futures", "serde", "serde_json", "serde_with", + "tokio", + "tokio-stream", ] [[package]] @@ -1419,7 +1393,7 @@ version = "1.1.1" dependencies = [ "pop-launcher-plugins", "pop-launcher-service", - "smol", + "tokio", "tracing", "tracing-subscriber", ] @@ -1446,9 +1420,9 @@ dependencies = [ "serde", "serde_json", "slab", - "smol", "strsim", "sysfs-class", + "tokio", "tracing", "tracing-subscriber", "url", @@ -1463,9 +1437,7 @@ name = "pop-launcher-service" version = "1.1.1" dependencies = [ "anyhow", - "async-io", "async-oneshot", - "async-process", "async-trait", "flume", "futures", @@ -1479,8 +1451,9 @@ dependencies = [ "serde_json", "serde_with", "slab", - "smol", "strsim", + "tokio", + "tokio-stream", "toml", "tracing", "tracing-subscriber", @@ -1775,16 +1748,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "signal-hook" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" -dependencies = [ - "libc", - "signal-hook-registry", -] - [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1817,24 +1780,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" -[[package]] -name = "smol" -version = "1.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4" -dependencies = [ - "async-channel", - "async-executor", - "async-fs", - "async-io", - "async-lock", - "async-net", - "async-process", - "blocking", - "futures-lite", - "once_cell", -] - [[package]] name = "socket2" version = "0.4.4" @@ -1949,6 +1894,45 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "tokio" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +dependencies = [ + "bytes 1.1.0", + "libc", + "memchr", + "mio", + "once_cell", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.8" @@ -2127,6 +2111,12 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.79" diff --git a/Cargo.toml b/Cargo.toml index 6a653f6..e8ce2d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,17 @@ edition = "2018" members = ["bin", "plugins", "service"] [dependencies] -blocking = "1.2.0" const_format = "0.2.22" dirs = "4.0.0" futures = "0.3.21" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" serde_with = "1.12.0" + +[dependencies.tokio] +version = "1.17.0" +features = ["io-std", "io-util"] + +[dependencies.tokio-stream] +version = "0.1.8" +features = ["io-util"] \ No newline at end of file diff --git a/bin/Cargo.toml b/bin/Cargo.toml index 49420bf..80145d4 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -10,6 +10,9 @@ publish = false [dependencies] pop-launcher-plugins = { path = "../plugins" } pop-launcher-service = { path = "../service" } -smol = "1.2.5" tracing = "0.1.32" tracing-subscriber = { version = "0.3.9", features = ["env-filter"] } + +[dependencies.tokio] +version = "1.17.0" +features = ["rt"] \ No newline at end of file diff --git a/bin/src/main.rs b/bin/src/main.rs index 5ba4c2d..e48a0c2 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -3,10 +3,10 @@ use pop_launcher_plugins as plugins; use pop_launcher_service as service; -use smol::block_on; use std::io; -fn main() { +#[tokio::main(flavor = "current_thread")] +async fn main() { tracing_subscriber::fmt() .with_writer(io::stderr) .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) @@ -16,17 +16,17 @@ fn main() { let start = plugin.rfind('/').map(|v| v + 1).unwrap_or(0); let cmd = &plugin.as_str()[start..]; match cmd { - "calc" => block_on(plugins::calc::main()), - "desktop-entries" => block_on(plugins::desktop_entries::main()), - "find" => block_on(plugins::find::main()), - "files" => block_on(plugins::files::main()), - "pop-launcher" => block_on(service::main()), - "pop-shell" => block_on(plugins::pop_shell::main()), - "pulse" => block_on(plugins::pulse::main()), - "recent" => block_on(plugins::recent::main()), - "scripts" => block_on(plugins::scripts::main()), - "terminal" => block_on(plugins::terminal::main()), - "web" => block_on(plugins::web::main()), + "calc" => plugins::calc::main().await, + "desktop-entries" => plugins::desktop_entries::main().await, + "find" => plugins::find::main().await, + "files" => plugins::files::main().await, + "pop-launcher" => service::main().await, + "pop-shell" => plugins::pop_shell::main().await, + "pulse" => plugins::pulse::main().await, + "recent" => plugins::recent::main().await, + "scripts" => plugins::scripts::main().await, + "terminal" => plugins::terminal::main().await, + "web" => plugins::web::main().await, unknown => { eprintln!("unknown cmd: {}", unknown); } diff --git a/debian/rules b/debian/rules index 2e0ee35..459be27 100755 --- a/debian/rules +++ b/debian/rules @@ -2,6 +2,7 @@ VENDOR ?= 1 CLEAN ?= 1 +DEBUG ?= 0 DESTDIR=debian/tmp %: diff --git a/plugins/Cargo.toml b/plugins/Cargo.toml index d42a036..3ed3173 100644 --- a/plugins/Cargo.toml +++ b/plugins/Cargo.toml @@ -20,7 +20,6 @@ ron = "0.7.0" serde = "1.0.136" serde_json = "1.0.79" slab = "0.4.5" -smol = "1.2.5" strsim = "0.10.0" tracing = "0.1.32" tracing-subscriber = "0.3.9" @@ -35,3 +34,7 @@ anyhow = "1.0.56" flume = "0.10.12" dirs = "4.0.0" futures = "0.3.21" + +[dependencies.tokio] +version = "1.17.0" +features = ["fs", "io-std", "macros", "process", "rt"] \ No newline at end of file diff --git a/plugins/src/calc/mod.rs b/plugins/src/calc/mod.rs index 9646ee5..fe88c71 100644 --- a/plugins/src/calc/mod.rs +++ b/plugins/src/calc/mod.rs @@ -1,14 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-only // Copyright © 2021 System76 -use futures::{AsyncBufReadExt, AsyncWriteExt, StreamExt}; +use futures::StreamExt; use pop_launcher::*; use regex::Regex; -use smol::{ - process::{Command, Stdio}, - Unblock, +use std::{borrow::Cow, io, process::Stdio}; +use tokio::{ + io::{AsyncBufReadExt, AsyncWriteExt}, + process::Command, }; -use std::{borrow::Cow, io}; pub async fn main() { let mut requests = json_input_stream(async_stdin()); @@ -37,7 +37,7 @@ pub async fn main() { pub struct App { pub decimal_comma: bool, - out: Unblock, + out: tokio::io::Stdout, outcome: Option, regex: Regex, } @@ -158,14 +158,17 @@ async fn qcalc(regex: &mut Regex, expression: &str, decimal_comma: bool) -> Opti } }; - let mut reader = futures::io::BufReader::new(stdout).lines().skip(2); + let mut reader = tokio::io::BufReader::new(stdout).lines(); let mut output = String::new(); + let _ = reader.next_line().await; + let _ = reader.next_line().await; + fn has_issue(line: &str) -> bool { line.starts_with("error") || line.starts_with("warning") } - while let Some(Ok(line)) = reader.next().await { + while let Ok(Some(line)) = reader.next_line().await { let line = line.trim(); if line.is_empty() { @@ -260,9 +263,9 @@ mod tests { ); } - #[test] - fn approximate_result_formatting() { - let task = smol::spawn(async { + #[tokio::test] + async fn approximate_result_formatting() { + let task = tokio::spawn(async { let mut app = App { decimal_comma: false, ..Default::default() @@ -271,10 +274,8 @@ mod tests { app.outcome.take() }); - smol::block_on(async { - if let Some(result) = task.await { - assert_eq!("≈ 2.333333333", result); - } - }) + if let Some(result) = task.await.unwrap() { + assert_eq!("≈ 2.333333333", result); + } } } diff --git a/plugins/src/desktop_entries/mod.rs b/plugins/src/desktop_entries/mod.rs index c4a8162..bd27800 100644 --- a/plugins/src/desktop_entries/mod.rs +++ b/plugins/src/desktop_entries/mod.rs @@ -5,11 +5,12 @@ mod graphics; use crate::*; use freedesktop_desktop_entry::{default_paths, DesktopEntry, Iter as DesktopIter, PathSource}; -use futures::{AsyncWrite, StreamExt}; +use futures::StreamExt; use pop_launcher::*; use std::borrow::Cow; use std::hash::{Hash, Hasher}; use std::path::PathBuf; +use tokio::io::AsyncWrite; #[derive(Debug, Eq)] struct Item { diff --git a/plugins/src/files/mod.rs b/plugins/src/files/mod.rs index 263cb44..7acef91 100644 --- a/plugins/src/files/mod.rs +++ b/plugins/src/files/mod.rs @@ -3,8 +3,7 @@ use futures::prelude::*; use pop_launcher::*; -use smol::Unblock; -use std::{collections::BTreeMap, io, path::PathBuf}; +use std::{collections::BTreeMap, path::PathBuf}; #[derive(Clone)] struct Item { @@ -38,7 +37,7 @@ pub async fn main() { pub struct App { entries: BTreeMap>, home: PathBuf, - out: Unblock, + out: tokio::io::Stdout, search_results: Vec, } diff --git a/plugins/src/find/mod.rs b/plugins/src/find/mod.rs index 5f83723..cf1b5fe 100644 --- a/plugins/src/find/mod.rs +++ b/plugins/src/find/mod.rs @@ -3,11 +3,13 @@ use futures::*; use pop_launcher::*; -use smol::process::{Child, ChildStdout, Command, Stdio}; use std::cell::Cell; use std::io; use std::path::PathBuf; +use std::process::Stdio; use std::rc::Rc; +use tokio::io::AsyncBufReadExt; +use tokio::process::{Child, ChildStdout, Command}; enum Event { Activate(u32), @@ -37,12 +39,10 @@ pub async fn main() { Event::Activate(id) => { if let Some(selection) = app.search_results.get(id as usize) { let path = selection.clone(); - let handle = smol::spawn(async move { + tokio::spawn(async move { crate::xdg_open(&path); }); - handle.detach(); - crate::send(&mut app.out, PluginResponse::Close).await; } } @@ -114,7 +114,7 @@ pub async fn main() { struct SearchContext { pub active: Rc>, pub interrupt_rx: flume::Receiver<()>, - pub out: smol::Unblock, + pub out: tokio::io::Stdout, pub search_results: Vec, } @@ -148,7 +148,7 @@ impl SearchContext { tracing::debug!("searching for {}", search); let (mut child, mut stdout) = match query(&search).await { - Ok((child, stdout)) => (child, futures::io::BufReader::new(stdout).lines()), + Ok((child, stdout)) => (child, tokio::io::BufReader::new(stdout).lines()), Err(why) => { tracing::error!("failed to spawn fdfind process: {}", why); @@ -176,19 +176,16 @@ impl SearchContext { 'stream: loop { let interrupt = async { let _ = self.interrupt_rx.recv_async().await; - None + Ok(None) }; - match crate::or(interrupt, stdout.next()).await { - Some(result) => match result { - Ok(line) => append = line, - Err(why) => { - tracing::error!("error on stdout line read: {}", why); - break 'stream; - } - }, - - None => break 'stream, + match crate::or(interrupt, stdout.next_line()).await { + Ok(Some(line)) => append = line, + Ok(None) => break 'stream, + Err(why) => { + tracing::error!("error on stdout line read: {}", why); + break 'stream; + } } self.append(id, append).await; @@ -201,7 +198,7 @@ impl SearchContext { } let _ = child.kill(); - let _ = child.status().await; + let _ = child.wait().await; } } diff --git a/plugins/src/lib.rs b/plugins/src/lib.rs index e806aa7..a32d515 100644 --- a/plugins/src/lib.rs +++ b/plugins/src/lib.rs @@ -12,9 +12,9 @@ pub mod scripts; pub mod terminal; pub mod web; -use futures::{AsyncWrite, AsyncWriteExt}; use pop_launcher::PluginResponse; use std::{borrow::Cow, ffi::OsStr, future::Future, path::Path}; +use tokio::io::{AsyncWrite, AsyncWriteExt}; pub async fn send(tx: &mut W, response: PluginResponse) { if let Ok(mut bytes) = serde_json::to_string(&response) { @@ -47,5 +47,5 @@ pub fn mime_from_path(path: &Path) -> Cow<'static, str> { /// Launches a file with its default appplication via `xdg-open`. pub fn xdg_open>(file: S) { - let _ = smol::process::Command::new("xdg-open").arg(file).spawn(); + let _ = tokio::process::Command::new("xdg-open").arg(file).spawn(); } diff --git a/plugins/src/pop_shell/mod.rs b/plugins/src/pop_shell/mod.rs index 74951ad..cdc5546 100644 --- a/plugins/src/pop_shell/mod.rs +++ b/plugins/src/pop_shell/mod.rs @@ -3,10 +3,11 @@ use crate::*; use freedesktop_desktop_entry as fde; -use futures::{AsyncWrite, AsyncWriteExt, StreamExt}; +use futures::StreamExt; use pop_launcher::*; use serde::{Deserialize, Serialize}; use std::{convert::TryFrom, fs, path::PathBuf, sync::Arc}; +use tokio::io::{AsyncWrite, AsyncWriteExt}; use zbus::Connection; use zvariant::{Signature, Type}; diff --git a/plugins/src/pulse/mod.rs b/plugins/src/pulse/mod.rs index 1ac6af3..0ea1868 100644 --- a/plugins/src/pulse/mod.rs +++ b/plugins/src/pulse/mod.rs @@ -4,7 +4,6 @@ use async_pidfd::AsyncPidFd; use futures::prelude::*; use pop_launcher::*; -use smol::Unblock; use std::io; struct Selection { @@ -15,7 +14,7 @@ struct Selection { pub struct App { selections: Vec, - out: Unblock, + out: tokio::io::Stdout, } impl Default for App { @@ -77,7 +76,7 @@ impl App { let sinks = pactl_sinks(); while let Ok(id) = sinks.recv_async().await { - handles.push(smol::spawn(async move { + handles.push(tokio::spawn(async move { let args = &[arg1, id.as_str(), arg2]; let _ = command_spawn(cmd, args).await; })); @@ -136,25 +135,25 @@ async fn command_spawn(cmd: &str, args: &[&str]) -> io::Result<()> { fn pactl_sinks() -> flume::Receiver { let (tx, rx) = flume::bounded(4); - smol::spawn(async move { - let child = smol::process::Command::new("pactl") + tokio::spawn(async move { + let child = tokio::process::Command::new("pactl") .env("LANG", "C") .args(&["list", "sinks"]) - .stdout(smol::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) .spawn(); if let Ok(mut child) = child { if let Some(stdout) = child.stdout.take() { - let mut lines = futures::io::BufReader::new(stdout).lines(); - while let Some(Ok(line)) = lines.next().await { + use tokio::io::AsyncBufReadExt; + let mut lines = tokio::io::BufReader::new(stdout).lines(); + while let Ok(Some(line)) = lines.next_line().await { if let Some(stripped) = line.strip_prefix("Sink #") { let _ = tx.send_async(stripped.trim().to_owned()).await; } } } } - }) - .detach(); + }); rx } diff --git a/plugins/src/recent/mod.rs b/plugins/src/recent/mod.rs index 0d4b57b..968de7d 100644 --- a/plugins/src/recent/mod.rs +++ b/plugins/src/recent/mod.rs @@ -5,12 +5,11 @@ use futures::prelude::*; use gtk::prelude::*; use pop_launcher::*; use slab::Slab; -use smol::Unblock; -use std::{borrow::Cow, io}; +use std::borrow::Cow; pub struct App { manager: gtk::RecentManager, - out: Unblock, + out: tokio::io::Stdout, uris: Slab, } diff --git a/plugins/src/scripts/mod.rs b/plugins/src/scripts/mod.rs index 0946cd0..8c93dd7 100644 --- a/plugins/src/scripts/mod.rs +++ b/plugins/src/scripts/mod.rs @@ -5,13 +5,12 @@ use crate::*; use pop_launcher::*; use flume::Sender; -use futures::{AsyncBufReadExt, StreamExt}; -use smol::process::{Command, Stdio}; +use futures::StreamExt; use std::collections::VecDeque; -use std::{ - io, - path::{Path, PathBuf}, -}; +use std::path::{Path, PathBuf}; +use std::process::Stdio; +use tokio::io::AsyncBufReadExt; +use tokio::process::Command; const LOCAL_PATH: &str = ".local/share/pop-launcher/scripts"; const SYSTEM_ADMIN_PATH: &str = "/etc/pop-launcher/scripts"; @@ -42,7 +41,7 @@ pub async fn main() { pub struct App { scripts: Vec, - out: smol::Unblock, + out: tokio::io::Stdout, } impl App { @@ -156,9 +155,9 @@ async fn load_from(path: &Path, paths: &mut VecDeque, tx: Sender