Skip to content

Commit 4c7bd1a

Browse files
committed
Some preliminary work for better error notification
I need to fix the issue where it will ignore an MER older than 5 because it checks for the lock file in the MER first but 4 and older don't have it. In the meantime I started some prep work for better error notification to the user when something goes wrong.
1 parent b8241b4 commit 4c7bd1a

File tree

2 files changed

+116
-8
lines changed

2 files changed

+116
-8
lines changed

src/main.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use log::error;
1111
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
1212
use rfd::FileDialog;
1313
use simplelog::{CombinedLogger, Config, LevelFilter, SimpleLogger, WriteLogger};
14-
use slint::{Model, ModelRc, VecModel};
14+
use slint::{Model, ModelRc, Timer, TimerMode, VecModel};
1515
use std::{
1616
borrow::BorrowMut, cell::RefCell, collections::HashMap, fs::File, path::PathBuf, rc::Rc,
1717
};
@@ -99,6 +99,30 @@ fn main() -> Result<(), slint::PlatformError> {
9999
}
100100
});
101101

102+
let info_file_model_start = file_model.clone();
103+
//let info_timer = vec![Timer::default(); file_model.row_count()];
104+
let mut info_timers: Vec<Timer> = (0..file_model.row_count()).map(|_i|Timer::default()).collect();
105+
ui.on_slide_over(move |idx| {
106+
let idx = idx as usize;
107+
if idx >= info_timers.len() {
108+
info_timers.extend((info_timers.len()..idx+1).map(|_| Timer::default()));
109+
}
110+
let info_file_model_stop = info_file_model_start.clone();
111+
let info_file_model_start = info_file_model_start.as_ref();
112+
if let Some(mut fi) = info_file_model_start.row_data(idx) {
113+
fi.note_vis = true;
114+
info_file_model_start.set_row_data(idx, fi);
115+
}
116+
info_timers[idx].start(TimerMode::SingleShot, std::time::Duration::from_secs(3), move || {
117+
let info_file_model_stop = info_file_model_stop.clone();
118+
let info_file_model_stop = info_file_model_stop.as_ref();
119+
if let Some(mut fi) = info_file_model_stop.row_data(idx) {
120+
fi.note_vis = false;
121+
info_file_model_stop.set_row_data(idx, fi);
122+
}
123+
})
124+
});
125+
102126
ui.run()
103127
}
104128

@@ -123,12 +147,16 @@ fn process_paths(files: Vec<PathBuf>) -> HashMap<String, PathBuf> {
123147
fn get_file_info(files: &HashMap<String, PathBuf>) -> Vec<file_info> {
124148
files
125149
.par_iter()
150+
//need to do this differently....what if the version is older than 5 there the is_protected
151+
//would return an error...but I still want to display the version
126152
.filter_map(|(name, file)| match is_protected(&file) {
127153
Ok(lckd) => match get_version(&file) {
128154
Ok(ver) => Some(file_info {
129155
locked: lckd,
130156
file_name: name.into(),
131157
file_ver: ver.to_string().into(),
158+
note: "test".into(),
159+
note_vis: false,
132160
}),
133161
Err(e) => {
134162
error!(
@@ -143,7 +171,14 @@ fn get_file_info(files: &HashMap<String, PathBuf>) -> Vec<file_info> {
143171
"Unable to get file information from {}. Reason: {e}",
144172
file.display()
145173
);
146-
None
174+
//None
175+
Some(file_info {
176+
locked: true,
177+
file_name: name.into(),
178+
file_ver: get_version(&file).unwrap().to_string().into(),
179+
note: "test".into(),
180+
note_vis: false,
181+
})
147182
}
148183
})
149184
.collect()

ui/appwindow.slint

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,95 @@ export struct file_info {
44
locked: bool,
55
file_name: string,
66
file_ver: string,
7+
note: string,
8+
note_vis: bool,
9+
}
10+
11+
component SlideOver inherits Rectangle {
12+
in property<string> info: "test string";
13+
visible: false;
14+
VerticalLayout {
15+
Rectangle {
16+
Text {
17+
text: info;
18+
vertical-alignment: center;
19+
font-weight: 900;
20+
horizontal-stretch: 1;
21+
font-size: 10pt;
22+
}
23+
}
24+
Rectangle {
25+
height: 2%;
26+
width: 100%;
27+
background: yellow;
28+
}
29+
}
730
}
831

932
component FileInfo inherits HorizontalLayout {
10-
in property<file_info> info : {
33+
34+
in-out property<file_info> info : {
1135
locked: true,
1236
file-name: "My File.mer",
1337
file-ver: "12.0",
38+
note: "test",
39+
note_vis: false,
1440
};
1541

1642
property<color> icon-color: info.locked ? #ff4343 : #107c10;
1743

1844
callback unlock(string);
45+
callback slide-over();
1946

2047
padding: 5px;
21-
height: 48px;
48+
height: 50px;
2249

2350
Rectangle {
2451
border-width: 1px;
25-
HorizontalLayout {
52+
inf-so := SlideOver {
53+
info: root.info.note;
54+
visible: info.note-vis;
55+
states [
56+
vis when self.visible : {
57+
x: 0px;
58+
}
59+
not-vis when !self.visible : {
60+
x: root.width * -1;
61+
}
62+
]
63+
64+
animate x {
65+
duration: 1000ms;
66+
easing: ease-in-out;
67+
}
68+
}
69+
HorizontalBox {
2670
lbl := Text {
2771
text: "\{info.file_name}: (v\{info.file_ver})";
2872
vertical-alignment: center;
2973
font-weight: 900;
3074
horizontal-stretch: 1;
3175
font-size: 10pt;
3276
}
77+
info-icon := Image {
78+
//this circle question icon is a temporary one while I'm offline, I just had it on my machine
79+
source: @image-url("../assets/icons/circle-question.svg");
80+
colorize: yellow;
81+
height: 100%;
82+
width: self.height;
83+
visible: info.note != "";
84+
info-ta := TouchArea {
85+
clicked => {
86+
slide-over();
87+
}
88+
}
89+
}
3390
icon := Image {
34-
source: info.locked ? @image-url("../assets/icons/protected.svg" ) : @image-url("../assets/icons/unlocked.svg");
91+
source: info.locked ? @image-url("../assets/icons/protected.svg") : @image-url("../assets/icons/unlocked.svg");
3592
colorize: icon-color;
3693
height: 100%;
3794
width: self.height;
38-
y: 1px;
95+
//y: 1px;
3996
horizontal-stretch: 0;
4097

4198
icn-ta := TouchArea {
@@ -58,6 +115,20 @@ component FileInfo inherits HorizontalLayout {
58115
}
59116
]
60117
}
118+
119+
states [
120+
vis when !inf-so.visible : {
121+
x: 0px;
122+
}
123+
not-vis when inf-so.visible : {
124+
x: root.width;
125+
}
126+
]
127+
128+
animate x {
129+
duration: 1000ms;
130+
easing: ease-in-out;
131+
}
61132
}
62133
}
63134
}
@@ -70,17 +141,19 @@ export component AppWindow inherits Window {
70141

71142
callback unlock(string, int);
72143
callback select_files();
144+
callback slide_over(int);
73145

74146
vl := VerticalLayout {
75147
ListView {
76148
for f_info[idx] in files : FileInfo {
77149
info: f_info;
78150
unlock => { unlock(f_info.file_name, idx); }
151+
slide-over => { slide-over(idx); }
79152
}
80153
}
81154
Button {
82155
text: "Select Files";
83156
clicked => { select_files(); }
84157
}
85158
}
86-
}
159+
}

0 commit comments

Comments
 (0)