mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
implement background message handler (worker)
This commit is contained in:
185
Cargo.lock
generated
185
Cargo.lock
generated
@@ -20,6 +20,12 @@ version = "1.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cairo-rs"
|
name = "cairo-rs"
|
||||||
version = "0.15.10"
|
version = "0.15.10"
|
||||||
@@ -389,6 +395,15 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.1.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libadwaita"
|
name = "libadwaita"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -427,6 +442,16 @@ version = "0.2.121"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
|
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.14"
|
version = "0.4.14"
|
||||||
@@ -451,6 +476,28 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mio"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"wasi",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_cpus"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.10.0"
|
version = "1.10.0"
|
||||||
@@ -482,6 +529,29 @@ dependencies = [
|
|||||||
"system-deps",
|
"system-deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pest"
|
name = "pest"
|
||||||
version = "2.1.3"
|
version = "2.1.3"
|
||||||
@@ -570,6 +640,15 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "relm4"
|
name = "relm4"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
@@ -605,6 +684,12 @@ dependencies = [
|
|||||||
"semver",
|
"semver",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -629,6 +714,15 @@ version = "1.0.136"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
@@ -641,6 +735,16 @@ version = "1.8.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "socket2"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.89"
|
version = "1.0.89"
|
||||||
@@ -685,6 +789,37 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.18.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"libc",
|
||||||
|
"memchr",
|
||||||
|
"mio",
|
||||||
|
"num_cpus",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
|
"socket2",
|
||||||
|
"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]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.5.8"
|
version = "0.5.8"
|
||||||
@@ -699,6 +834,7 @@ name = "toolbox-tuner"
|
|||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"relm4",
|
"relm4",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -725,6 +861,12 @@ version = "0.9.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@@ -746,3 +888,46 @@ name = "winapi-x86_64-pc-windows-gnu"
|
|||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.36.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
relm4 = {version="0.4", features = ["libadwaita", "macros"]}
|
relm4 = {version="0.4", features = ["libadwaita", "macros"]}
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
|
||||||
[package.metadata.appimage]
|
[package.metadata.appimage]
|
||||||
auto_link = true
|
auto_link = true
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use relm4::{
|
use relm4::{factory::FactoryVecDeque, RelmApp};
|
||||||
factory::{FactoryVecDeque},
|
|
||||||
RelmApp,
|
|
||||||
};
|
|
||||||
use toolbx::ToolbxContainer;
|
use toolbx::ToolbxContainer;
|
||||||
use ui::app::model::AppModel;
|
use ui::app::model::AppModel;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use relm4::factory::DynamicIndex;
|
use relm4::factory::DynamicIndex;
|
||||||
|
|
||||||
|
use super::model::ToolbxEntry;
|
||||||
|
|
||||||
pub enum AppMsg {
|
pub enum AppMsg {
|
||||||
ShowToolboxSettingsRequest,
|
ShowToolboxSettingsRequest,
|
||||||
ShowToolboxAppsRequest,
|
ShowToolboxAppsRequest,
|
||||||
ToolbxContainerToggleStartStop(DynamicIndex),
|
ToolbxContainerToggleStartStop(DynamicIndex),
|
||||||
|
ToolbxContainerChanged(DynamicIndex, ToolbxEntry),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ pub mod model;
|
|||||||
pub mod toolbox_list;
|
pub mod toolbox_list;
|
||||||
pub mod update;
|
pub mod update;
|
||||||
pub mod widgets;
|
pub mod widgets;
|
||||||
|
pub mod workers;
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
use relm4::{
|
use relm4::{factory::FactoryVecDeque, Model};
|
||||||
factory::{FactoryVecDeque},
|
|
||||||
Model,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{toolbx::ToolbxContainer, ui::components::AppComponents};
|
use crate::{toolbx::ToolbxContainer, ui::components::AppComponents};
|
||||||
|
|
||||||
use super::{messages::AppMsg, widgets::AppWidgets};
|
use super::{messages::AppMsg, widgets::AppWidgets};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub struct ToolbxEntry {
|
pub struct ToolbxEntry {
|
||||||
pub toolbx_container: ToolbxContainer,
|
pub toolbx_container: ToolbxContainer,
|
||||||
pub changing_status: bool,
|
pub changing_status: bool,
|
||||||
@@ -17,6 +15,13 @@ impl ToolbxEntry {
|
|||||||
pub fn update_container(&mut self, container: ToolbxContainer) {
|
pub fn update_container(&mut self, container: ToolbxContainer) {
|
||||||
std::mem::replace::<ToolbxContainer>(&mut self.toolbx_container, container);
|
std::mem::replace::<ToolbxContainer>(&mut self.toolbx_container, container);
|
||||||
}
|
}
|
||||||
|
pub fn update_entry(&mut self, container: ToolbxEntry) {
|
||||||
|
std::mem::replace::<ToolbxContainer>(
|
||||||
|
&mut self.toolbx_container,
|
||||||
|
container.toolbx_container,
|
||||||
|
);
|
||||||
|
self.changing_status = container.changing_status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppModel {
|
pub struct AppModel {
|
||||||
@@ -32,7 +37,8 @@ impl Model for AppModel {
|
|||||||
impl AppModel {
|
impl AppModel {
|
||||||
pub fn update_toolbxes<I>(&mut self, toolbox_iter: I)
|
pub fn update_toolbxes<I>(&mut self, toolbox_iter: I)
|
||||||
where
|
where
|
||||||
I: Iterator<Item = ToolbxContainer>, {
|
I: Iterator<Item = ToolbxContainer>,
|
||||||
|
{
|
||||||
// Update each toolbx entry if there were changes to it
|
// Update each toolbx entry if there were changes to it
|
||||||
// TODO: deal with the removal of toolboxes
|
// TODO: deal with the removal of toolboxes
|
||||||
for tbx_update in toolbox_iter {
|
for tbx_update in toolbox_iter {
|
||||||
@@ -40,14 +46,19 @@ impl AppModel {
|
|||||||
let mut exists = false;
|
let mut exists = false;
|
||||||
for (index, tbx_entry) in self.toolboxes.iter().enumerate() {
|
for (index, tbx_entry) in self.toolboxes.iter().enumerate() {
|
||||||
if tbx_update.name == tbx_entry.toolbx_container.name {
|
if tbx_update.name == tbx_entry.toolbx_container.name {
|
||||||
self.toolboxes.get_mut(index).map(|x| x.update_container(tbx_update.clone()));
|
self.toolboxes
|
||||||
|
.get_mut(index)
|
||||||
|
.map(|x| x.update_container(tbx_update.clone()));
|
||||||
exists = true;
|
exists = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
println!("{}", tbx_update.name);
|
println!("{}", tbx_update.name);
|
||||||
self.toolboxes.push_back(ToolbxEntry { toolbx_container: tbx_update, changing_status: false})
|
self.toolboxes.push_back(ToolbxEntry {
|
||||||
|
toolbx_container: tbx_update,
|
||||||
|
changing_status: false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use relm4::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
toolbx::{ToolbxContainer, ToolbxStatus},
|
toolbx::ToolbxStatus,
|
||||||
ui::ui_strings::{
|
ui::ui_strings::{
|
||||||
APP_ICON, APP_TOOLTIP, SETTINGS_ICON, SETTINGS_TOOLTIP, SHUTDOWN_ICON, SHUTDOWN_TOOLTIP,
|
APP_ICON, APP_TOOLTIP, SETTINGS_ICON, SETTINGS_TOOLTIP, SHUTDOWN_ICON, SHUTDOWN_TOOLTIP,
|
||||||
START_ICON, START_TOOLTIP, TERMINAL_ICON, TERMINAL_TOOLTIP, UPDATE_ICON, UPDATE_TOOLTIP,
|
START_ICON, START_TOOLTIP, TERMINAL_ICON, TERMINAL_TOOLTIP, UPDATE_ICON, UPDATE_TOOLTIP,
|
||||||
@@ -33,7 +33,6 @@ impl FactoryPrototype for ToolbxEntry {
|
|||||||
type Msg = AppMsg;
|
type Msg = AppMsg;
|
||||||
|
|
||||||
fn init_view(&self, key: &DynamicIndex, sender: Sender<Self::Msg>) -> Self::Widgets {
|
fn init_view(&self, key: &DynamicIndex, sender: Sender<Self::Msg>) -> Self::Widgets {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
suffix_box = >k::Box{
|
suffix_box = >k::Box{
|
||||||
append = >k::AspectFrame{
|
append = >k::AspectFrame{
|
||||||
@@ -107,7 +106,10 @@ impl FactoryPrototype for ToolbxEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let subtitle = format!("created {}\n{}", self.toolbx_container.created, self.toolbx_container.image);
|
let subtitle = format!(
|
||||||
|
"created {}\n{}",
|
||||||
|
self.toolbx_container.created, self.toolbx_container.image
|
||||||
|
);
|
||||||
|
|
||||||
let index = key.clone();
|
let index = key.clone();
|
||||||
|
|
||||||
@@ -150,7 +152,11 @@ impl FactoryPrototype for ToolbxEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
FactoryWidgets { action_row, status_button, status_spinner}
|
FactoryWidgets {
|
||||||
|
action_row,
|
||||||
|
status_button,
|
||||||
|
status_spinner,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(
|
fn view(
|
||||||
@@ -160,19 +166,21 @@ impl FactoryPrototype for ToolbxEntry {
|
|||||||
) {
|
) {
|
||||||
println!("updated {}", key.current_index());
|
println!("updated {}", key.current_index());
|
||||||
|
|
||||||
|
|
||||||
// fixme: IDEALY this is would be done with message handling and only if the request actually is done
|
// fixme: IDEALY this is would be done with message handling and only if the request actually is done
|
||||||
|
|
||||||
if self.changing_status {
|
if self.changing_status {
|
||||||
widgets.status_button.set_sensitive(false);
|
widgets.status_button.set_sensitive(false);
|
||||||
widgets.status_button.set_child(Some(&widgets.status_spinner));
|
widgets
|
||||||
|
.status_button
|
||||||
|
.set_child(Some(&widgets.status_spinner));
|
||||||
widgets.status_spinner.start();
|
widgets.status_spinner.start();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
match self.toolbx_container.status {
|
match self.toolbx_container.status {
|
||||||
ToolbxStatus::Running => {
|
ToolbxStatus::Running => {
|
||||||
widgets.status_button.set_icon_name(SHUTDOWN_ICON);
|
widgets.status_button.set_icon_name(SHUTDOWN_ICON);
|
||||||
widgets.status_button.set_tooltip_text(Some(SHUTDOWN_TOOLTIP));
|
widgets
|
||||||
|
.status_button
|
||||||
|
.set_tooltip_text(Some(SHUTDOWN_TOOLTIP));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
widgets.status_button.set_icon_name(START_ICON);
|
widgets.status_button.set_icon_name(START_ICON);
|
||||||
@@ -182,8 +190,6 @@ impl FactoryPrototype for ToolbxEntry {
|
|||||||
widgets.status_button.set_sensitive(true);
|
widgets.status_button.set_sensitive(true);
|
||||||
widgets.status_spinner.stop();
|
widgets.status_spinner.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn root_widget(widgets: &Self::Widgets) -> &Self::Root {
|
fn root_widget(widgets: &Self::Widgets) -> &Self::Root {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{messages::AppMsg, model::AppModel};
|
use super::{messages::AppMsg, model::AppModel, workers::AsyncHandlerMsg};
|
||||||
|
|
||||||
impl AppUpdate for AppModel {
|
impl AppUpdate for AppModel {
|
||||||
fn update(&mut self, msg: AppMsg, components: &AppComponents, _sender: Sender<AppMsg>) -> bool {
|
fn update(&mut self, msg: AppMsg, components: &AppComponents, _sender: Sender<AppMsg>) -> bool {
|
||||||
@@ -27,23 +27,38 @@ impl AppUpdate for AppModel {
|
|||||||
}
|
}
|
||||||
AppMsg::ToolbxContainerToggleStartStop(index) => {
|
AppMsg::ToolbxContainerToggleStartStop(index) => {
|
||||||
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
|
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
|
||||||
|
|
||||||
match toolbx_container.toolbx_container.status {
|
match toolbx_container.toolbx_container.status {
|
||||||
ToolbxStatus::Exited | ToolbxStatus::Configured => {
|
ToolbxStatus::Exited | ToolbxStatus::Configured => {
|
||||||
toolbx_container.changing_status = true;
|
toolbx_container.changing_status = true;
|
||||||
// Send message to background worker to start
|
components
|
||||||
//toolbx_container.toolbx_container.start();
|
.async_handler
|
||||||
|
.sender()
|
||||||
|
.blocking_send(AsyncHandlerMsg::StartToolbx(
|
||||||
|
index,
|
||||||
|
toolbx_container.clone(),
|
||||||
|
))
|
||||||
|
.expect("Receiver dropped");
|
||||||
}
|
}
|
||||||
ToolbxStatus::Running => {
|
ToolbxStatus::Running => {
|
||||||
toolbx_container.changing_status = true;
|
toolbx_container.changing_status = true;
|
||||||
// send message to beackground worker to stop
|
components
|
||||||
//toolbx_container.toolbx_container.stop();
|
.async_handler
|
||||||
|
.sender()
|
||||||
|
.blocking_send(AsyncHandlerMsg::StopToolbx(
|
||||||
|
index,
|
||||||
|
toolbx_container.clone(),
|
||||||
|
))
|
||||||
|
.expect("Receiver dropped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: tell button to reactivate somehow
|
// TODO: tell button to reactivate somehow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AppMsg::ToolbxContainerChanged(index, container) => {
|
||||||
|
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
|
||||||
|
toolbx_container.update_entry(container);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use relm4::{
|
|||||||
prelude::{BoxExt, GtkWindowExt, OrientableExt, WidgetExt},
|
prelude::{BoxExt, GtkWindowExt, OrientableExt, WidgetExt},
|
||||||
traits::AdwApplicationWindowExt,
|
traits::AdwApplicationWindowExt,
|
||||||
},
|
},
|
||||||
gtk::{self, SelectionMode, Align, PolicyType},
|
gtk::{self, Align, PolicyType, SelectionMode},
|
||||||
WidgetPlus, Widgets,
|
WidgetPlus, Widgets,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
67
src/ui/app/workers.rs
Normal file
67
src/ui/app/workers.rs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
use relm4::factory::DynamicIndex;
|
||||||
|
use relm4::{send, MessageHandler, Sender};
|
||||||
|
use tokio::runtime::{Builder, Runtime};
|
||||||
|
use tokio::sync::mpsc::{channel, Sender as TokioSender};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
messages::AppMsg,
|
||||||
|
model::{AppModel, ToolbxEntry},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Code adapted from https://relm4.org/book/stable/message_handler.html
|
||||||
|
pub struct AsyncHandler {
|
||||||
|
_rt: Runtime,
|
||||||
|
sender: TokioSender<AsyncHandlerMsg>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum AsyncHandlerMsg {
|
||||||
|
StopToolbx(DynamicIndex, ToolbxEntry),
|
||||||
|
StartToolbx(DynamicIndex, ToolbxEntry),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MessageHandler<AppModel> for AsyncHandler {
|
||||||
|
type Msg = AsyncHandlerMsg;
|
||||||
|
type Sender = TokioSender<AsyncHandlerMsg>;
|
||||||
|
|
||||||
|
fn init(_parent_model: &AppModel, parent_sender: Sender<AppMsg>) -> Self {
|
||||||
|
let (sender, mut rx) = channel::<AsyncHandlerMsg>(10);
|
||||||
|
|
||||||
|
let rt = Builder::new_multi_thread()
|
||||||
|
.worker_threads(8)
|
||||||
|
.enable_time()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
rt.spawn(async move {
|
||||||
|
while let Some(msg) = rx.recv().await {
|
||||||
|
let parent_sender = parent_sender.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
|
match msg {
|
||||||
|
AsyncHandlerMsg::StopToolbx(index, mut tbx) => {
|
||||||
|
tbx.toolbx_container.stop();
|
||||||
|
tbx.changing_status = false;
|
||||||
|
send! {parent_sender, AppMsg::ToolbxContainerChanged(index, tbx)};
|
||||||
|
}
|
||||||
|
AsyncHandlerMsg::StartToolbx(index, mut tbx) => {
|
||||||
|
tbx.toolbx_container.start();
|
||||||
|
tbx.changing_status = false;
|
||||||
|
send! {parent_sender, AppMsg::ToolbxContainerChanged(index, tbx)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AsyncHandler { _rt: rt, sender }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send(&self, msg: Self::Msg) {
|
||||||
|
self.sender.blocking_send(msg).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sender(&self) -> Self::Sender {
|
||||||
|
self.sender.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
use relm4::RelmComponent;
|
use relm4::RelmComponent;
|
||||||
|
use relm4::RelmMsgHandler;
|
||||||
use relm4::Sender;
|
use relm4::Sender;
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
@@ -6,6 +7,7 @@ use self::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::app::model::AppModel;
|
use super::app::model::AppModel;
|
||||||
|
use super::app::workers::AsyncHandler;
|
||||||
|
|
||||||
pub mod toolbox_apps;
|
pub mod toolbox_apps;
|
||||||
pub mod toolbox_settings;
|
pub mod toolbox_settings;
|
||||||
@@ -14,4 +16,5 @@ pub mod toolbox_settings;
|
|||||||
pub struct AppComponents {
|
pub struct AppComponents {
|
||||||
pub toolbox_settings_dialog: RelmComponent<ToolboxSettingsDialogModel, AppModel>,
|
pub toolbox_settings_dialog: RelmComponent<ToolboxSettingsDialogModel, AppModel>,
|
||||||
pub toolbox_apps_dialog: RelmComponent<ToolboxAppDialogModel, AppModel>,
|
pub toolbox_apps_dialog: RelmComponent<ToolboxAppDialogModel, AppModel>,
|
||||||
|
pub async_handler: RelmMsgHandler<AsyncHandler, AppModel>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user