Skip to content

Commit

Permalink
fix: restore bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Horbin-Magician committed Oct 20, 2024
1 parent 8fc2e6a commit f3ae886
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/module/screen_shotter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,27 @@ impl ScreenShotter{
}

fn restore_pin_wins(&self) -> Result<(), Box<dyn Error>> {
let record = ShotterRecord::global().lock()
let mut record = ShotterRecord::global().lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
let shotters = record.get_shotters();

let mut max_id = *self.max_pin_win_id.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());

let mut invalid_shotter_ids = Vec::new();
for (id, shotter) in shotters {
let id = id.parse::<u32>()?;
if (id+1) > max_id { max_id = id+1; }

let img_buffer = ShotterRecord::load_record_img(id)?; // TODO: delete when load error
let img_buffer;
if let Ok(img) = ShotterRecord::load_record_img(id) {
img_buffer = img;
} else {
invalid_shotter_ids.push(id);
log_util::log_error(format!("Error in restore_pin_wins: can not load img, id: {}", id));
continue;
}

let message_sender_clone = self.message_sender.clone();
let rect = Rect{x: shotter.rect.0, y: shotter.rect.1, width: shotter.rect.2, height: shotter.rect.3};

Expand Down Expand Up @@ -484,6 +493,11 @@ impl ScreenShotter{
.insert(id, pin_win);
}

for id in invalid_shotter_ids {
ShotterRecord::del_record_img(id)?;
record.del_shotter(id)?;
}

*self.max_pin_win_id.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner()) = max_id;

Expand Down
4 changes: 2 additions & 2 deletions src/module/screen_shotter/pin_win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ impl PinWin {

let _ = pin_window.show();

// TODO: try to use other way
{ // trick: fix the bug of error scale_factor
let scale_factor = pin_window.window().scale_factor();
println!("scale_factor: {}; true_scale_factor: {}", scale_factor, true_scale_factor);
if scale_factor != true_scale_factor {
pin_window.set_zoom_factor(((scale_factor / true_scale_factor) * 100.) as i32);
pin_window.set_extra_zoom_factor(((scale_factor / true_scale_factor) * 100.) as i32);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/ui/screen_shotter/pin_win.slint
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ export component PinWindow inherits BaseWindow {
in property <length> img_x;
in property <length> img_y;
in-out property <int> zoom_factor: 100; // neet to be divided by one hundred
in-out property <int> extra_zoom_factor: 100;
in-out property <int> zoom_delta: 2; // neet to be divided by one hundred
in-out property <length> img_width;
in-out property <length> img_height;

in-out property <length> delta_img_width: 0px;
in-out property <length> delta_img_height: 0px;

in-out property <length> win_width: ((img_width + delta_img_width) * zoom_factor / 100) + win_border_width * 2;
in-out property <length> win_height: ((img_height + delta_img_height) * zoom_factor / 100) + win_border_width * 2;
in-out property <length> win_width: ((img_width + delta_img_width) * zoom_factor / 100 * extra_zoom_factor / 100) + win_border_width * 2;
in-out property <length> win_height: ((img_height + delta_img_height) * zoom_factor / 100 * extra_zoom_factor / 100) + win_border_width * 2;

in-out property <bool> is_stick_x: false;
in-out property <bool> is_stick_y: false;
Expand Down

0 comments on commit f3ae886

Please sign in to comment.