Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 将设置界面独立为一个窗口 #75

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true

[*rs]
indent_size = 4

[*.md]
max_line_length = off
insert_final_newline = false

[*.yml]
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod resource_location;
mod should_silence;
mod system_notification;
mod update_available;
mod setting_page;

pub use self::auto_launch::{auto_launch_setting, set_auto_launch};
pub use clipboard::copy_image;
Expand All @@ -28,3 +29,4 @@ pub use request_refer_image::request_refer_image;
pub use resource_location::{get_app_cache_path, get_app_config_path};
pub use should_silence::should_silence;
pub use system_notification::send_system_notification;
pub use setting_page::{close_setting_page, open_setting_page};
24 changes: 24 additions & 0 deletions src-tauri/src/commands/setting_page.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use tauri::{command, AppHandle, Manager, WindowEvent};

#[command]
pub async fn open_setting_page(handle: AppHandle) {
Comment on lines +3 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里面的都是tauri的api返回的Result,可以将接口返回写为 Result<(), tauri::Error> 然后去除内部的unwrap

let setting_page = handle.get_window("settings").unwrap();
// 居主页面之中
setting_page.center().unwrap();
setting_page.show().unwrap();
setting_page.set_focus().unwrap();
setting_page
.clone()
.on_window_event(move |event| {
if let WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
setting_page.hide().unwrap();
}
});
}

#[command]
pub async fn close_setting_page(handle: AppHandle) {
let setting_window = handle.get_window("settings").unwrap();
setting_window.hide().unwrap();
}
Comment on lines +3 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关窗口这个不需要rust这边来,前端就有接口关

7 changes: 5 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::commands::{
auto_launch_setting, back_preview, copy_image, front_logger, get_app_cache_path,
get_app_config_path, get_item, get_monitor_info, hide_notification, is_debug, message_beep,
quit, read_detail, request_refer_image, send_request, send_system_notification,
set_auto_launch, set_item, should_silence,
set_auto_launch, set_item, should_silence, open_setting_page, close_setting_page,
};
use crate::setup::logger::init_logger;
use crate::setup::system_tray::new_system_tray;
Expand All @@ -30,6 +30,7 @@ fn main() {
let builder = Builder::default()
.setup(|app| {
let window = app.get_window("main").expect("cannot found main window");
window.center().unwrap();
let args = app.get_cli_matches()?.args;
if let Some(arg) = args.get("hidden") {
if arg.occurrences == 0 {
Expand Down Expand Up @@ -76,7 +77,9 @@ fn main() {
hide_notification,
is_debug,
send_system_notification,
should_silence
should_silence,
open_setting_page,
close_setting_page,
]);

let app = builder
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod logger;
pub mod system_tray;
pub mod window_decoration;
17 changes: 16 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,28 @@
"fullscreen": false,
"visible": false,
"label": "main",
"height": 640,
"height": 720,
"resizable": true,
"title": "小刻食堂",
"width": 1280,
"minWidth": 1280,
"minHeight": 640
},
{
"decorations": false,
"fullscreen": false,
"visible": false,
"url": "/#/settings",
"label": "settings",
"height": 640,
"resizable": true,
"title": "设置",
"width": 720,
"minWidth": 720,
"minHeight": 640,
"fileDropEnabled": false,
"maximizable": false
},
{
"label": "background",
"visible": false,
Expand Down
8 changes: 8 additions & 0 deletions src/api/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ export async function bootStartSetting(isBoot: boolean): Promise<boolean> {
export async function getBootStartSetting(): Promise<boolean> {
return await invoke<boolean>("auto_launch_setting");
}

export async function openSettingPage() {
return await invoke<void>("open_setting_page");
}

export async function closeSettingPage() {
return await invoke<void>("close_setting_page");
}
91 changes: 3 additions & 88 deletions src/components/AppTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<v-btn
icon="fas fa-gear"
variant="text"
@click="setting.show = true"
@click="openSettingPage"
></v-btn>
<v-btn
icon="fas fa-minus"
Expand Down Expand Up @@ -111,29 +111,10 @@
>
<donate-page @close="donate.show = false"></donate-page>
</v-dialog>

<v-dialog
v-model="setting.show"
persistent
transition="dialog-top-transition"
width="400"
>
<setting-page :versionState="setting.versionState" @checkUpdate="version.getNewestVersion"
@close="setting.close"></setting-page>
</v-dialog>
<v-dialog
v-model="version.show"
persistent
transition="dialog-top-transition"
width="600"
>
<version-page :force="version.force" :versionInfo="version.version_info"
@close="version.show = false"></version-page>
</v-dialog>
</template>

<script lang="ts" setup>
import {onMounted, reactive, ref} from "vue";
import { reactive, ref} from "vue";
import storage from "../api/operations/localStorage";
import {
DatasourceItem,
Expand All @@ -144,11 +125,7 @@ import datasourceConfigOperate from "../api/operations/datasourceConfig";
import searchWordEvent from "../api/operations/searchWordEvent";
import operate from "../api/operations/operate";
import DonatePage from "./DonatePage.vue";
import SettingPage from "./SettingPage.vue";
import VersionPage from "./VersionPage.vue";
import {getVersion, DesktopVersion} from "@/api/resourceFetcher/version";
import updater, {VersionStateType} from "../api/operations/updater";
import {isPermissionGranted, requestPermission, sendNotification} from "@tauri-apps/api/notification";
import { openSettingPage } from "@/api/function";

const winMax = ref(false);

Expand Down Expand Up @@ -270,68 +247,6 @@ const donate = reactive({
show: false,
});

const setting = reactive({
show: false,
// updater setting
versionState: VersionStateType.Unknown,
close() {
setting.show = false;
setting.versionState = VersionStateType.Unknown;
},
});

const ErrVersionInfo: DesktopVersion = {
baidu: "<Missing>",
baidu_text: "<Missing>",
description: "<Missing>",
dmg: "<Missing>",
exe: "<Missing>",
force: false,
last_force_version: "<Missing>",
spare_dmg: "<Missing>",
spare_exe: "<Missing>",
version: "<Missing>",
};

const version = reactive<{
show: boolean,
version_info: DesktopVersion,
force: boolean,
getNewestVersion(): void
}>({
show: false,
force: false,
version_info: ErrVersionInfo,
async getNewestVersion() {
try {
if (setting.show) {
setting.versionState = VersionStateType.Newest;
}
const currentVersion = await getVersion()
version.version_info = currentVersion.data.data
// version.force = await updater.judgmentVersion(version.version_info.last_force_version)
version.show = await updater.judgmentVersion(version.version_info.version)
if (version.show) {
setting.versionState = VersionStateType.UpdateAvailable
}
} catch (error: any) {
console.log("Failure loading New Version")
if (!await isPermissionGranted()) {
await requestPermission()
}
sendNotification({
title: "小刻出错了!",
icon: "/asserts/icon.png",
body: error.toString()
})
}
}
});

onMounted(() => {
version.getNewestVersion();
})

</script>

<style lang="scss" rel="stylesheet/scss">
Expand Down
Loading