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 027c8ac commit 9496c5c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ debug-mold:
$(build-evn) $(run-evn) mold --run cargo run --features=desktop

debug-local:
$(run-evn) ./target/debug/slint-template-desktop
$(run-evn) ./target/debug/slint-template

release-local:
$(run-evn) ./target/release/slint-template-desktop
$(run-evn) ./target/release/slint-template

build-desktop-debug-mold:
$(build-evn) $(run-evn) mold --run cargo build --features=desktop
Expand Down
10 changes: 5 additions & 5 deletions src/config/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ pub fn save(conf: data::Config) -> Result<()> {
impl Config {
pub fn init(&mut self) -> Result<()> {
let app_name = if cfg!(not(target_os = "android")) {
"slint"
"slint-template"
} else {
if cfg!(debug_assertions) {
"xyz.heng30.slint"
"xyz.heng30.slint-template"
} else {
"xyz.heng30.slint"
"xyz.heng30.slint-template"
}
};

Expand All @@ -100,8 +100,8 @@ impl Config {
}

fn init_config(&mut self, app_dirs: &AppDirs) -> Result<()> {
self.db_path = app_dirs.data_dir.join("slint.db");
self.config_path = app_dirs.config_dir.join("slint.toml");
self.db_path = app_dirs.data_dir.join("slint-template.db");
self.config_path = app_dirs.config_dir.join("slint-template.toml");
self.cache_dir = app_dirs.data_dir.join("cache");

if self.appid.is_empty() {
Expand Down
16 changes: 13 additions & 3 deletions ui/logic.slint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Store, SettingUI, TabIndex} from "store.slint";
import { Store, SettingUI, TabIndex, SettingDetailIndex} from "store.slint";

export global Logic {
callback update-cache-size();
Expand All @@ -19,7 +19,17 @@ export global Logic {
inner-tr(Store.is-cn, text)
}

public function switch-tab(tab-index: TabIndex) {
Store.current-tab-index = tab-index;
public function switch-setting-detail(index: SettingDetailIndex) {
if (Store.current-setting-detail-index == index) {
return;
}
Store.current-setting-detail-index = index;
}

public function switch-tab(index: TabIndex) {
if (Store.current-tab-index == index) {
return;
}
Store.current-tab-index = index;
}
}
5 changes: 2 additions & 3 deletions ui/panel/bodyer/panel.slint
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Home } from "./home.slint";
import { Setting } from "./setting.slint";

export component Bodyer inherits Rectangle {
if TabIndex.Home == Store.current-tab-index : Home {}
if TabIndex.Setting == Store.current-tab-index : Setting {}
if TabIndex.Home == Store.current-tab-index: Home { }
if TabIndex.Setting == Store.current-tab-index: Setting { }
}

10 changes: 4 additions & 6 deletions ui/panel/bodyer/setting.slint
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ component Body inherits VerticalLayout {
}

export component Setting inherits Rectangle {
private property <int> selected-account-index;

if Store.current-setting-detail-index == SettingDetailIndex.Home: Body { }

if Store.current-setting-detail-index != SettingDetailIndex.Home: Rectangle {
Expand All @@ -229,27 +227,27 @@ export component Setting inherits Rectangle {
Util.show-toast(Logic.tr("Input cann't be empty"), ToastStatus.Warning);
return;
}
Store.current-setting-detail-index = SettingDetailIndex.Home;
Logic.switch-setting-detail(SettingDetailIndex.Home);
Logic.set-setting-ui(self.get());
}
}

if Store.current-setting-detail-index == SettingDetailIndex.About: About {
back => {
Store.current-setting-detail-index = SettingDetailIndex.Home;
Logic.switch-setting-detail(SettingDetailIndex.Home);
}
}

if Store.current-setting-detail-index == SettingDetailIndex.Help: Help {
entries: Store.helps;
back => {
Store.current-setting-detail-index = SettingDetailIndex.Home;
Logic.switch-setting-detail(SettingDetailIndex.Home);
}
}

if Store.current-setting-detail-index == SettingDetailIndex.Donate: Donate {
back => {
Store.current-setting-detail-index = SettingDetailIndex.Home;
Logic.switch-setting-detail(SettingDetailIndex.Home);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions ui/store.slint
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export global Store {
in-out property <bool> is-show-landing-page;

in-out property <TabIndex> current-tab-index: TabIndex.Home;

in-out property <float> current_switch-setting-detail-rate;
in-out property <SettingDetailIndex> current-setting-detail-index: SettingDetailIndex.Home;

in-out property <bool> is-cn: setting-ui.language == "cn";
Expand All @@ -35,11 +37,11 @@ export global Store {
};

in-out property <[string]> helps: is-cn ? [
"配置文件保存目录: ~/.config/",
"数据库保存目录: ~/.local/share/",
"配置文件保存目录: ~/.config/slint-template",
"数据库保存目录: ~/.local/share/slint-template",
] : [
"Config directory: ~/.config/",
"Data directory: ~/.local/share/",
"Config directory: ~/.config/slint-template",
"Data directory: ~/.local/share/slint-template",
];

}

0 comments on commit 9496c5c

Please sign in to comment.