refactor: use libcosmic::dialog and make rfd optional

This commit is contained in:
Michael Aaron Murphy 2024-01-22 08:42:18 +01:00
parent 6a74db14ed
commit a1c80efe69
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
3 changed files with 38 additions and 34 deletions

39
Cargo.lock generated
View file

@ -998,7 +998,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-config" name = "cosmic-config"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"atomicwrites", "atomicwrites",
"cosmic-config-derive", "cosmic-config-derive",
@ -1013,7 +1013,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-config-derive" name = "cosmic-config-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"quote", "quote",
"syn 1.0.109", "syn 1.0.109",
@ -1036,7 +1036,6 @@ dependencies = [
"log", "log",
"notify", "notify",
"patch", "patch",
"rfd",
"rust-embed", "rust-embed",
"serde", "serde",
"syntect", "syntect",
@ -1083,7 +1082,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-theme" name = "cosmic-theme"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"almost", "almost",
"cosmic-config", "cosmic-config",
@ -2612,7 +2611,7 @@ dependencies = [
[[package]] [[package]]
name = "iced" name = "iced"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"iced_accessibility", "iced_accessibility",
"iced_core", "iced_core",
@ -2627,7 +2626,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_accessibility" name = "iced_accessibility"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"accesskit", "accesskit",
"accesskit_winit", "accesskit_winit",
@ -2636,7 +2635,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_core" name = "iced_core"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"instant", "instant",
@ -2652,7 +2651,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_futures" name = "iced_futures"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"futures", "futures",
"iced_core", "iced_core",
@ -2665,7 +2664,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_graphics" name = "iced_graphics"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"bytemuck", "bytemuck",
@ -2688,7 +2687,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_renderer" name = "iced_renderer"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"iced_graphics", "iced_graphics",
"iced_tiny_skia", "iced_tiny_skia",
@ -2701,7 +2700,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_runtime" name = "iced_runtime"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"iced_futures", "iced_futures",
@ -2711,7 +2710,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_style" name = "iced_style"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"iced_core", "iced_core",
"once_cell", "once_cell",
@ -2721,7 +2720,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_tiny_skia" name = "iced_tiny_skia"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cosmic-text", "cosmic-text",
@ -2739,7 +2738,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_wgpu" name = "iced_wgpu"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"bytemuck", "bytemuck",
@ -2759,7 +2758,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_widget" name = "iced_widget"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"iced_renderer", "iced_renderer",
"iced_runtime", "iced_runtime",
@ -2773,7 +2772,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_winit" name = "iced_winit"
version = "0.12.0" version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"iced_graphics", "iced_graphics",
"iced_runtime", "iced_runtime",
@ -3091,7 +3090,7 @@ checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
[[package]] [[package]]
name = "libcosmic" name = "libcosmic"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#4e18199444aecbc60f25a12e8adb91926aa5e653" source = "git+https://github.com/pop-os/libcosmic?branch=dialog#6e8afc8341a4b5ef9ab453485ddf1acbbf256b72"
dependencies = [ dependencies = [
"apply", "apply",
"ashpd", "ashpd",
@ -3113,6 +3112,7 @@ dependencies = [
"iced_winit", "iced_winit",
"lazy_static", "lazy_static",
"palette", "palette",
"rfd",
"slotmap", "slotmap",
"taffy", "taffy",
"thiserror", "thiserror",
@ -4678,10 +4678,11 @@ dependencies = [
[[package]] [[package]]
name = "rfd" name = "rfd"
version = "0.12.1" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c9e7b57df6e8472152674607f6cc68aa14a748a3157a857a94f516e11aeacc2" checksum = "c0d8ab342bcc5436e04d3a4c1e09e17d74958bfaddf8d5fad6f85607df0f994f"
dependencies = [ dependencies = [
"ashpd",
"block", "block",
"dispatch", "dispatch",
"glib-sys", "glib-sys",

View file

@ -13,8 +13,6 @@ lexical-sort = "0.3.1"
log = "0.4.20" log = "0.4.20"
patch = "0.7.0" patch = "0.7.0"
notify = "6.1.1" notify = "6.1.1"
#TODO: this is using gtk for file dialogues
rfd = { version = "0.12.0", optional = true }
serde = { version = "1", features = ["serde_derive"] } serde = { version = "1", features = ["serde_derive"] }
tokio = { version = "1", features = ["process", "time"] } tokio = { version = "1", features = ["process", "time"] }
# Extra syntax highlighting # Extra syntax highlighting
@ -35,9 +33,9 @@ features = ["syntect", "vi"]
[dependencies.libcosmic] [dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic" git = "https://github.com/pop-os/libcosmic"
branch = "dialog"
default-features = false default-features = false
features = ["tokio", "winit"] features = ["tokio", "winit"]
#path = "../libcosmic"
#TODO: clean up and send changes upstream #TODO: clean up and send changes upstream
[dependencies.systemicons] [dependencies.systemicons]
@ -47,8 +45,13 @@ git = "https://github.com/jackpot51/systemicons"
fork = "0.1" fork = "0.1"
[features] [features]
default = ["rfd", "wgpu"] default = ["xdg-portal", "wgpu"]
# Use RFD for file chooser dialogs
rfd = ["libcosmic/rfd"]
# Enable GPU rendering with WGPU
wgpu = ["libcosmic/wgpu"] wgpu = ["libcosmic/wgpu"]
# Use XDG portal dialogs on Linux
xdg-portal = ["libcosmic/xdg-portal"]
[patch.crates-io] [patch.crates-io]
smithay-client-toolkit = { git = "https://github.com/pop-os/client-toolkit", branch = "wayland-resize" } smithay-client-toolkit = { git = "https://github.com/pop-os/client-toolkit", branch = "wayland-resize" }

View file

@ -3,7 +3,9 @@
use cosmic::{ use cosmic::{
app::{message, Command, Core, Settings}, app::{message, Command, Core, Settings},
cosmic_config::{self, CosmicConfigEntry}, cosmic_config::{self, CosmicConfigEntry},
cosmic_theme, executor, cosmic_theme,
dialog::file_chooser,
executor,
font::Font, font::Font,
iced::{ iced::{
clipboard, event, clipboard, event,
@ -1437,17 +1439,15 @@ impl Application for App {
} }
}, },
Message::OpenFileDialog => { Message::OpenFileDialog => {
#[cfg(feature = "rfd")] return cosmic::command::future(async {
return Command::perform( if let Ok(response) = file_chooser::open::Dialog::new().open_file().await {
async { if let Ok(path) = response.url().to_file_path() {
if let Some(handle) = rfd::AsyncFileDialog::new().pick_file().await { return message::app(Message::OpenFile(path));
message::app(Message::OpenFile(handle.path().to_owned()))
} else {
message::none()
} }
}, }
|x| x,
); message::none()
});
} }
Message::OpenFile(path) => { Message::OpenFile(path) => {
self.open_tab(Some(path)); self.open_tab(Some(path));