Skip to content

Commit

Permalink
[*] refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
heng30 committed Aug 14, 2024
1 parent 4e27ee1 commit 027c8ac
Show file tree
Hide file tree
Showing 35 changed files with 503 additions and 500 deletions.
2 changes: 1 addition & 1 deletion src/logic/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use slint::ComponentHandle;

pub fn init(ui: &AppWindow) {
ui.global::<AboutSetting>().set_title(slint::format!(
"sollaw {}",
"slint-template {}",
if VERSION.is_empty() {
"v0.0.1"
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/logic/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub fn init(ui: &AppWindow) {
ui.global::<Logic>().on_copy_to_clipboard(move |msg| {
let ui = ui_handle.unwrap();
match copy_to_clipboard(&msg) {
Err(e) => toast_warn!(ui, format!("{}. {}: {e:?}", tr("复制失败"), tr("原因"))),
_ => toast_success!(ui, tr("复制成功")),
Err(e) => toast_warn!(ui, format!("{}. {}: {e:?}", tr("Copy failed"), tr("Reason"))),
_ => toast_success!(ui, tr("Copy success")),
}
});

Expand All @@ -65,7 +65,7 @@ pub fn init(ui: &AppWindow) {
let ui = ui_handle.unwrap();
match copy_from_clipboard() {
Err(e) => {
toast_warn!(ui, format!("{}. {}: {e:?}", tr("粘贴失败"), tr("原因")));
toast_warn!(ui, format!("{}. {}: {e:?}", tr("Paste failed"), tr("Reason")));
slint::SharedString::default()
}
Ok(msg) => msg.into(),
Expand Down
12 changes: 6 additions & 6 deletions src/logic/confirm_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::slint_generatedAppWindow::{AppWindow, Logic};
use crate::slint_generatedAppWindow::{AppWindow, Util, Logic};
use slint::ComponentHandle;

pub fn init(ui: &AppWindow) {
let ui_handle = ui.as_weak();
ui.global::<Logic>()
ui.global::<Util>()
.on_handle_confirm_dialog(move |handle_type, _user_data| {
let _ui = ui_handle.unwrap();
let ui = ui_handle.unwrap();

match handle_type.as_str() {
// "remove-all-cache" => {
// ui.global::<Logic>().invoke_remove_all_cache();
// }
"remove-all-cache" => {
ui.global::<Logic>().invoke_remove_all_cache();
}
_ => (),
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/logic/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn init(ui: &AppWindow) {
.set_is_show_landing_page(config::is_first_run());

ui.global::<Logic>()
.on_tr(move |_is_cn, text| tr(text.as_str()).into());
.on_inner_tr(move |_is_cn, text| tr(text.as_str()).into());

let ui_handle = ui.as_weak();
ui.global::<Logic>().on_get_setting_ui(move || {
Expand Down
30 changes: 20 additions & 10 deletions src/logic/toast.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use crate::slint_generatedAppWindow::{AppWindow, ToastSetting, Util};
use crate::slint_generatedAppWindow::{AppWindow, ToastSetting, ToastStatus, Util};
use slint::{ComponentHandle, Timer, TimerMode, Weak};

#[macro_export]
macro_rules! toast_warn {
($ui:expr, $msg:expr) => {
$ui.global::<crate::slint_generatedAppWindow::Util>()
.invoke_show_toast(slint::format!("{}", $msg), "warning".into())
.invoke_show_toast(
slint::format!("{}", $msg),
crate::slint_generatedAppWindow::ToastStatus::Warning,
)
};
}

#[macro_export]
macro_rules! toast_success {
($ui:expr, $msg:expr) => {
$ui.global::<crate::slint_generatedAppWindow::Util>()
.invoke_show_toast(slint::format!("{}", $msg), "success".into())
.invoke_show_toast(
slint::format!("{}", $msg),
crate::slint_generatedAppWindow::ToastStatus::Success,
)
};
}

Expand All @@ -22,7 +28,10 @@ macro_rules! toast_success {
macro_rules! toast_info {
($ui:expr, $msg:expr) => {
$ui.global::<crate::slint_generatedAppWindow::Util>()
.invoke_show_toast(slint::format!("{}", $msg), "info".into())
.invoke_show_toast(
slint::format!("{}", $msg),
crate::slint_generatedAppWindow::ToastStatus::Info,
)
};
}

Expand All @@ -31,7 +40,7 @@ pub fn async_toast_warn(ui: Weak<AppWindow>, msg: String) {
let _ = slint::invoke_from_event_loop(move || {
ui.unwrap()
.global::<Util>()
.invoke_show_toast(slint::format!("{}", msg), "warning".into());
.invoke_show_toast(slint::format!("{}", msg), ToastStatus::Warning);
});
}

Expand All @@ -40,7 +49,7 @@ pub fn async_toast_success(ui: Weak<AppWindow>, msg: String) {
let _ = slint::invoke_from_event_loop(move || {
ui.unwrap()
.global::<Util>()
.invoke_show_toast(slint::format!("{}", msg), "success".into());
.invoke_show_toast(slint::format!("{}", msg), ToastStatus::Success);
});
}

Expand All @@ -49,14 +58,14 @@ pub fn async_toast_info(ui: Weak<AppWindow>, msg: String) {
let _ = slint::invoke_from_event_loop(move || {
ui.unwrap()
.global::<Util>()
.invoke_show_toast(slint::format!("{}", msg), "info".into());
.invoke_show_toast(slint::format!("{}", msg), ToastStatus::Info);
});
}

pub fn init(ui: &AppWindow) {
let timer = Timer::default();
let ui_handle = ui.as_weak();
ui.global::<Util>().on_show_toast(move |msg, msg_type| {
ui.global::<Util>().on_show_toast(move |msg, status| {
let ui = ui_handle.unwrap();

if timer.running() {
Expand All @@ -69,13 +78,14 @@ pub fn init(ui: &AppWindow) {
2
};

ui.global::<ToastSetting>().invoke_set(msg, msg_type);
ui.global::<ToastSetting>().invoke_set(msg, status);

timer.start(
TimerMode::SingleShot,
std::time::Duration::from_secs(interval),
move || {
ui.global::<ToastSetting>().invoke_set("".into(), "".into());
ui.global::<ToastSetting>()
.invoke_set("".into(), ToastStatus::None);
},
);
});
Expand Down
Loading

0 comments on commit 027c8ac

Please sign in to comment.