Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Nov 30, 2023
1 parent e2cf02c commit 407c2d4
Show file tree
Hide file tree
Showing 39 changed files with 3,040 additions and 1,980 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ log = "0.4"
nix = "0.27.1"
num_cpus = "1.15.0"
pad = "0.1.6"
passwords = "3.1.16"
qrcode = "0.12.0"
rand = "0.8"
ritehash = "0.2.0"
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ futures.workspace = true
js-sys.workspace = true
log.workspace = true
pad.workspace = true
passwords.workspace = true
qrcode.workspace = true
ritehash.workspace = true
separator.workspace = true
Expand Down
19 changes: 8 additions & 11 deletions core/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
use crate::runtime::runtime;
use workflow_core::channel::{
unbounded, Receiver, RecvError, SendError, Sender as ChannelSender, TryRecvError, TrySendError,
};

#[derive(Debug, Clone)]
pub struct Sender<T> {
ctx: Option<egui::Context>,
sender: ChannelSender<T>,
}

impl<T> Sender<T> {
pub fn new(ctx: Option<egui::Context>, sender: ChannelSender<T>) -> Self {
Self { ctx, sender }
pub fn new(sender: ChannelSender<T>) -> Self {
Self { sender }
}

pub async fn send(&self, msg: T) -> Result<(), SendError<T>> {
self.sender.send(msg).await?;
if let Some(ctx) = &self.ctx {
ctx.request_repaint();
}
runtime().request_repaint();
Ok(())
}

pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>> {
self.sender.try_send(msg)?;
if let Some(ctx) = &self.ctx {
ctx.request_repaint();
}
runtime().request_repaint();

Ok(())
}

Expand All @@ -45,10 +42,10 @@ pub struct Channel<T = ()> {
}

impl<T> Channel<T> {
pub fn unbounded(ctx: Option<egui::Context>) -> Self {
pub fn unbounded() -> Self {
let (sender, receiver) = unbounded();
Self {
sender: Sender::new(ctx, sender),
sender: Sender::new(sender),
receiver,
}
}
Expand Down
18 changes: 6 additions & 12 deletions core/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
self.list.is_empty()
}

pub fn push(&mut self, v: T) {
pub fn push_unchecked(&mut self, v: T) {
self.map.insert(*v.id(), v.clone());
self.list.push(v);
}
Expand All @@ -48,10 +48,7 @@ where
if self.map.insert(*v.id(), v.clone()).is_some() {
let id = v.id();
let index = self.list.iter().position(|item| item.id() == id).unwrap_or_else(|| {
panic!(
"Collection::replace_or_insert(): failed to find index for id: {} while inserting: {:?}",
id.to_hex(), v
)
panic!("Collection::replace_or_insert(): failed to find index for id: {} while inserting: {:?}", id.to_hex(), v)
});
let _ = std::mem::replace(&mut self.list[index], v);
} else {
Expand All @@ -63,10 +60,7 @@ where
if self.map.insert(*v.id(), v.clone()).is_some() {
let id = v.id();
let index = self.list.iter().position(|item| item.id() == id).unwrap_or_else(|| {
panic!(
"Collection::replace_or_insert(): failed to find index for id: {} while inserting: {:?}",
id.to_hex(), v
)
panic!("Collection::replace_or_insert(): failed to find index for id: {} while inserting: {:?}", id.to_hex(), v)
});
let _ = std::mem::replace(&mut self.list[index], v);
} else {
Expand Down Expand Up @@ -112,15 +106,15 @@ where
self.map.clear();
}

pub fn extend(&mut self, iter: impl IntoIterator<Item = T>) {
pub fn extend_unchecked(&mut self, iter: impl IntoIterator<Item = T>) {
for v in iter {
self.push(v);
self.push_unchecked(v);
}
}

pub fn load(&mut self, iter: impl IntoIterator<Item = T>) {
self.clear();
self.extend(iter);
self.extend_unchecked(iter);
}
}

Expand Down
Loading

0 comments on commit 407c2d4

Please sign in to comment.