diff --git a/Cargo.lock b/Cargo.lock index af53535..072728d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,16 +166,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "better-panic" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa9e1d11a268684cbd90ed36370d7577afb6c62d912ddff5c15fc34343e5036" -dependencies = [ - "backtrace", - "console", -] - [[package]] name = "bit-set" version = "0.5.3" @@ -435,18 +425,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "console" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "windows-sys 0.42.0", -] - [[package]] name = "const_panic" version = "0.2.7" @@ -512,7 +490,6 @@ version = "0.1.0" dependencies = [ "apply", "async-channel", - "better-panic", "bytecheck", "color-eyre", "derive_setters", @@ -526,6 +503,7 @@ dependencies = [ "rkyv", "rust-embed", "slotmap", + "tokio", ] [[package]] @@ -922,12 +900,6 @@ dependencies = [ "syn", ] -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - [[package]] name = "error-code" version = "2.3.1" @@ -1625,6 +1597,7 @@ source = "git+https://github.com/pop-os/libcosmic?rev=843919e44f0a00c33c29358359 dependencies = [ "futures", "log", + "tokio", "wasm-bindgen-futures", "wasm-timer", ] @@ -1925,6 +1898,7 @@ dependencies = [ "lazy_static", "palette", "slotmap", + "tokio", ] [[package]] @@ -3538,6 +3512,18 @@ dependencies = [ "displaydoc", ] +[[package]] +name = "tokio" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" +dependencies = [ + "autocfg", + "num_cpus", + "pin-project-lite", + "windows-sys 0.42.0", +] + [[package]] name = "toml" version = "0.5.11" diff --git a/Cargo.toml b/Cargo.toml index 747802e..391a715 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ rust-version = "1.65.0" [dependencies] apply = "0.3.0" async-channel = "1.8.0" -better-panic = "0.3.0" bytecheck = "0.6.9" color-eyre = "0.6.2" derive_setters = "0.1.5" @@ -20,6 +19,7 @@ regex = "1.7.1" rkyv = { version = "0.7.39", features = ["validation"]} rust-embed = "6.4.2" slotmap = "1.0.6" +tokio = "1.25.0" [dependencies.i18n-embed] version = "0.13.8" @@ -29,14 +29,14 @@ features = ["fluent-system", "desktop-requester"] git = "https://github.com/pop-os/libcosmic" rev = "843919e44f0a00c33c29358359be5b4bfa41ab00" default-features = false -features = ["debug", "winit", "dyrend"] +features = ["debug", "winit", "dyrend", "tokio"] [profile.dev] -opt-level = 3 +opt-level = 2 incremental = true [profile.release] opt-level = "s" overflow-checks = true lto = "thin" -incremental = false \ No newline at end of file +incremental = false diff --git a/src/app.rs b/src/app.rs index 09b30dc..421a45c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -66,7 +66,7 @@ pub enum Message { } impl Application for SettingsApp { - type Executor = iced::executor::Default; + type Executor = cosmic::executor::single::Executor; type Flags = (); type Message = Message; type Theme = Theme; diff --git a/src/main.rs b/src/main.rs index 9978567..7cbea88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,6 @@ use i18n_embed::DesktopLanguageRequester; /// /// Returns error if iced fails to run the application. pub fn main() -> color_eyre::Result<()> { - better_panic::install(); color_eyre::install()?; if std::env::var("RUST_SPANTRACE").is_err() { diff --git a/src/page/mod.rs b/src/page/mod.rs index 0239752..725e346 100644 --- a/src/page/mod.rs +++ b/src/page/mod.rs @@ -5,13 +5,14 @@ pub mod desktop; pub mod networking; pub mod section; pub mod time; + pub use section::Section; pub mod sound; pub mod system; mod model; -pub use model::{Insert, Model}; +pub use model::{Insert, Model, PageTask}; use derive_setters::Setters; use slotmap::SlotMap; @@ -39,8 +40,8 @@ pub trait Page { #[must_use] #[allow(unused)] - fn load(page: Entity) -> crate::Message { - crate::Message::None + fn load(page: Entity) -> PageTask { + Box::pin(async move { crate::Message::None }) } } diff --git a/src/page/model.rs b/src/page/model.rs index fdba4f0..1d0bf19 100644 --- a/src/page/model.rs +++ b/src/page/model.rs @@ -4,15 +4,20 @@ use std::{ any::{Any, TypeId}, collections::HashMap, + future::Future, + pin::Pin, }; use crate::page::{self, section, Content, Meta, Page, Section}; +use cosmic::iced_native::command::{Action, Command}; use regex::Regex; use slotmap::{SecondaryMap, SlotMap, SparseSecondaryMap}; +pub type PageTask = Pin + Send>>; + pub struct Model { pub pages: SlotMap, - pub page_load: SecondaryMap crate::Message>, + pub page_load: SecondaryMap PageTask>, pub resource: HashMap>, pub storage: HashMap>>, pub sub_pages: SparseSecondaryMap>, @@ -81,19 +86,9 @@ impl Model { .and_then(|storage| storage.remove(id)); } - pub fn init_page(&mut self, id: page::Entity) -> Option> { + pub fn init_page(&mut self, id: page::Entity) -> Option> { if let Some(func) = self.page_load.get(id).copied() { - let (tx, rx) = async_channel::bounded(1); - - std::thread::spawn(move || { - let _res = tx.send_blocking(func(id)); - }); - - let future = async move { dbg!(rx.recv().await.unwrap_or(crate::Message::None)) }; - - return Some(cosmic::iced::Command::single( - cosmic::iced_native::command::Action::Future(Box::pin(future)), - )); + return Some(Command::single(Action::Future(func(id)))); } None @@ -102,6 +97,7 @@ impl Model { // Registers a new page in the settings panel. pub fn register(&mut self) -> Insert { let id = self.pages.insert(P::page()); + self.page_load.insert(id, P::load); if let Some(content) = P::content(&mut self.sections) { @@ -184,6 +180,8 @@ impl<'a> Insert<'a> { ..P::page() }); + self.model.page_load.insert(page, P::load); + if let Some(content) = P::content(&mut self.model.sections) { self.model.content.insert(page, content); } diff --git a/src/page/system/about.rs b/src/page/system/about.rs index a971912..552289f 100644 --- a/src/page/system/about.rs +++ b/src/page/system/about.rs @@ -1,6 +1,8 @@ // Copyright 2023 System76 // SPDX-License-Identifier: GPL-3.0-only +use std::future::Future; + use crate::page::{self, Content, Section}; use cosmic::{ iced::{ @@ -38,7 +40,7 @@ pub struct Info { impl Model { pub fn update(&mut self, message: Message) { match message { - Message::Info(info) => self.info = dbg!(info), + Message::Info(info) => self.info = info, } } } @@ -64,15 +66,17 @@ impl page::Page for Page { ]) } - fn load(page: page::Entity) -> crate::Message { - let info = Info { - windowing_system: std::env::var("XDG_SESSION_TYPE") - .ok() - .unwrap_or_else(|| fl!("unknown")), - ..Info::default() - }; + fn load(_page: page::Entity) -> crate::page::PageTask { + Box::pin(async move { + let info = Info { + windowing_system: std::env::var("XDG_SESSION_TYPE") + .ok() + .unwrap_or_else(|| fl!("unknown")), + ..Info::default() + }; - crate::Message::About(Message::Info(info)) + crate::Message::About(Message::Info(info)) + }) } }