From b66a8443352bf721997395ad052f872d20dbfde4 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 1 Sep 2023 20:26:18 +0800 Subject: [PATCH 01/34] =?UTF-8?q?:sparkles:=20=E5=90=8E=E5=8F=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/Cargo.toml | 4 +-- src-tauri/src/commands/front_logger.rs | 35 ++++++++++++++++++++++++++ src-tauri/src/commands/mod.rs | 2 ++ src-tauri/src/main.rs | 5 ++-- src/App.vue | 2 ++ src/api/operations/logger.ts | 32 +++++++++++++++++++++++ src/utils/backgroundUtil.ts | 9 +++++++ src/view/home/InfoAndTool.vue | 4 +-- src/view/home/TimeLine.vue | 10 +++++--- 9 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 src-tauri/src/commands/front_logger.rs create mode 100644 src/api/operations/logger.ts diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 19d0dde1..63b1261d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -3,7 +3,7 @@ name = "ceobe-canteen-desktop" version = "0.1.8" description = "小刻食堂的桌面端,恭喜你电脑有多了个和小刻一样喜欢吃东西的浏览器内核 " authors = ["FrozenString"] -license = "AGPL-3" +license="AGPL-3" repository = "https://github.com/Enraged-Dun-Cookie-Development-Team/Ceobe-Canteen-Electron" default-run = "ceobe-canteen-desktop" edition = "2021" @@ -16,7 +16,7 @@ tauri-build = { version = "1.4.0", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.4.0", features = ["notification-all", "dialog-message", "path-all", "protocol-all", "http-all", "window-all", "clipboard-all", "shell-open", "fs-read-file", "system-tray", "devtools"] } +tauri = { version = "1.4.0", features = ["notification-all", "dialog-message", "path-all", "protocol-all", "http-all", "window-all", "clipboard-all", "shell-open", "fs-read-file", "system-tray"] } reqwest = "0.11" base64 = "0.21.2" regex = "1" diff --git a/src-tauri/src/commands/front_logger.rs b/src-tauri/src/commands/front_logger.rs new file mode 100644 index 00000000..5c2fade0 --- /dev/null +++ b/src-tauri/src/commands/front_logger.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use tauri::command; +use tracing::{debug, error, info, instrument, trace, warn}; + +#[derive(Serialize, Deserialize)] +pub enum Level { + Trace, + Debug, + Info, + Warn, + Error, +} + +#[command] +#[instrument(skip_all, name = "FontEndLog")] +pub fn front_logger(level: Level, local: String, payload: Value) { + match level { + Level::Trace => { + trace!(logSource = "FontEnd", frontFile = local, payload = %payload); + } + Level::Debug => { + debug!(logSource = "FontEnd", frontFile = local, payload = %payload); + } + Level::Info => { + info!(logSource = "FontEnd", frontFile = local, payload = %payload); + } + Level::Warn => { + warn!(logSource = "FontEnd", frontFile = local, payload = %payload); + } + Level::Error => { + error!(logSource = "FontEnd", frontFile = local, payload = %payload); + } + } +} diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index 164af7d4..92b33556 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -6,6 +6,7 @@ mod quit; mod request_client; mod request_refer_image; mod update_available; +mod front_logger; pub use self::auto_launch::{auto_launch_setting, set_auto_launch}; pub use clipboard::copy_image; @@ -14,3 +15,4 @@ pub use preview_page::{back_preview, read_detail}; pub use quit::quit; pub use request_client::send_request; pub use request_refer_image::request_refer_image; +pub use front_logger::front_logger; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index dcb6bde5..f7dbfae7 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -14,7 +14,7 @@ use tauri::{generate_context, Builder, Context, Manager, WindowEvent}; use crate::commands::{ auto_launch_setting, back_preview, copy_image, get_item, quit, read_detail, - request_refer_image, send_request, set_auto_launch, set_item, + request_refer_image, send_request, set_auto_launch, set_item, front_logger }; use crate::setup::logger::init_logger; use crate::setup::system_tray::new_system_tray; @@ -60,7 +60,8 @@ fn main() { set_item, send_request, quit, - back_preview + back_preview, + front_logger, ]); let app = builder diff --git a/src/App.vue b/src/App.vue index 30ec3483..ab4dca8d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -10,6 +10,8 @@ import updater from "./api/operations/updater"; import {notification} from "@tauri-apps/api"; onMounted(()=>{ + + if (getCurrent().label == "main"){ console.log("checking update") updater.checkUpdate() diff --git a/src/api/operations/logger.ts b/src/api/operations/logger.ts new file mode 100644 index 00000000..917c820c --- /dev/null +++ b/src/api/operations/logger.ts @@ -0,0 +1,32 @@ +import {invoke} from "@tauri-apps/api"; + + +class Logger { + async call(level: "Debug" | "Info" | "Trace" | "Warn" | "Error", local: string, payload: Record) { + await invoke("front_logger", {level: level, local: local, payload: payload}); + } + + async info(local: string, payload: Record) { + await this.call("Info", local, payload); + } + + async debug(local: string, payload: Record) { + await this.call("Debug", local, payload); + } + + async trace(local: string, payload: Record) { + await this.call("Trace", local, payload); + } + + async warn(local: string, payload: Record) { + await this.call("Warn", local, payload); + } + + async error(local: string, payload: Record) { + await this.call("Error", local, payload); + } +} + +const logger = new Logger(); + +export default logger; \ No newline at end of file diff --git a/src/utils/backgroundUtil.ts b/src/utils/backgroundUtil.ts index 4457f7e0..bfe3f65d 100644 --- a/src/utils/backgroundUtil.ts +++ b/src/utils/backgroundUtil.ts @@ -10,6 +10,7 @@ import { } from "../api/resourceFetcher/datasourceList"; import { getCookieList } from "../api/resourceFetcher/cookieList"; import { UnlistenFn } from "@tauri-apps/api/event"; +import logger from "../api/operations/logger"; const CombineIdKey = "datasource-comb"; @@ -84,6 +85,13 @@ export class BackgroundRunner { update_cookie_id !== this.old_update_cookie_id) ) { console.log(this.datasource_comb_id, cookie_id, update_cookie_id); + await logger.info( + "backgroundUtil", + { + "combineId": this.datasource_comb_id, + "cookieId": cookie_id, + "updateCookieId": update_cookie_id + }); let cookies_data = await getCookieList( this.datasource_comb_id, cookie_id, @@ -107,6 +115,7 @@ export class BackgroundRunner { true, ); if (this.init_fetched) { + logger.info("backgroundUtil",{"module":"backgroundRunner","state":"SendNewCookie"}) operate.openNotificationWindow(cookie); } } diff --git a/src/view/home/InfoAndTool.vue b/src/view/home/InfoAndTool.vue index 38ce377d..6f084ea2 100644 --- a/src/view/home/InfoAndTool.vue +++ b/src/view/home/InfoAndTool.vue @@ -29,13 +29,13 @@ From 646efafcc1daf7211635f0f5ac7e7e15139eb350 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 1 Sep 2023 22:37:40 +0800 Subject: [PATCH 03/34] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=97=A0?= =?UTF-8?q?=E5=9B=BE=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/Notification.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/view/Notification.vue b/src/view/Notification.vue index 0c756ff2..e0b24cf0 100644 --- a/src/view/Notification.vue +++ b/src/view/Notification.vue @@ -4,7 +4,7 @@ @@ -38,6 +38,7 @@ import {Cookie} from "../api/resourceFetcher/cookieList"; import {UnlistenFn} from "@tauri-apps/api/event"; const info = ref({ + setImg:false, imgUrl: getImage("/assets/image/logo/icon.png"), dataSource: "", cookieTime: "", @@ -45,6 +46,7 @@ const info = ref({ }); const updatePageData = (newData: Cookie) => { + info.value.dataSource = newData.datasource; if (newData.timestamp.platform_precision !== "none") { info.value.cookieTime = new Date(newData.timestamp.platform!).toLocaleString(); @@ -53,6 +55,7 @@ const updatePageData = (newData: Cookie) => { let images = newData.default_cookie.images; if (images) { + info.value.setImg=true; if (newData.datasource.includes("微博")) { ceobeRequest .getHasRefererImageBase64(images[0].origin_url) @@ -61,9 +64,13 @@ const updatePageData = (newData: Cookie) => { }); } else { info.value.imgUrl = images[0].origin_url; + } } else { console.log("no image"); + info.value.imgUrl=getImage("/assets/image/logo/icon.png") + info.value.setImg=false; + } }; let unliten: UnlistenFn; From fc0c25f84fff6ab7222b62cf12d876b3bfa751d9 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 7 Sep 2023 22:41:19 +0800 Subject: [PATCH 04/34] =?UTF-8?q?:sparkles:=20=E9=80=9A=E7=9F=A5=E5=B8=A6?= =?UTF-8?q?=E5=A3=B0=E9=9F=B3=EF=BC=8C=E4=B8=94=E4=B8=8D=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/commands/mod.rs | 2 + src-tauri/src/commands/monitor_info.rs | 77 ++++++++++++++++++++++++++ src-tauri/src/commands/preview_page.rs | 3 +- src-tauri/src/main.rs | 4 +- src/api/operations/operate.ts | 21 +++++-- src/view/Notification.vue | 19 +++---- 6 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 src-tauri/src/commands/monitor_info.rs diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index 92b33556..7f236a95 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -7,6 +7,7 @@ mod request_client; mod request_refer_image; mod update_available; mod front_logger; +mod monitor_info; pub use self::auto_launch::{auto_launch_setting, set_auto_launch}; pub use clipboard::copy_image; @@ -16,3 +17,4 @@ pub use quit::quit; pub use request_client::send_request; pub use request_refer_image::request_refer_image; pub use front_logger::front_logger; +pub use monitor_info::{get_monitor_info,message_beep}; \ No newline at end of file diff --git a/src-tauri/src/commands/monitor_info.rs b/src-tauri/src/commands/monitor_info.rs new file mode 100644 index 00000000..5c7d7899 --- /dev/null +++ b/src-tauri/src/commands/monitor_info.rs @@ -0,0 +1,77 @@ +use serde::Serialize; + +use tauri::{command, PhysicalPosition, PhysicalSize, Window}; + +#[derive(Debug, Clone, Serialize)] +pub struct MonitorInfo { + work_space: PhysicalSize, + left_top: PhysicalPosition, +} + +#[command] +pub fn get_monitor_info(window: Window) -> tauri::Result { + #[cfg(not(windows))] + { + let window = _window; + let monitor = window + .primary_monitor()? + .expect("Cannot found Primary Monitor"); + + Ok(MonitorInfo { + work_space: *monitor.size(), + left_top: *monitor.position(), + }) + } + #[cfg(windows)] + { + use std::mem::size_of; + use windows::{ + Win32::{ + Graphics::{ + Gdi::{ + GetMonitorInfoW, + MonitorFromWindow, + MONITORINFO, + MONITOR_DEFAULTTOPRIMARY + } + } + } + }; + + let hwnd = window.hwnd()?; + let mut monitor_info = MONITORINFO { + cbSize: size_of::() as u32, + ..Default::default() + }; + + unsafe { + let monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); + GetMonitorInfoW(monitor, &mut monitor_info); + }; + let rect = monitor_info.rcWork; + + Ok(MonitorInfo { + work_space: PhysicalSize::new( + (rect.right - rect.left) as u32, + (rect.bottom - rect.top) as u32, + ), + left_top: PhysicalPosition::new(rect.left, rect.top), + }) + } +} + +#[command] +pub fn message_beep() { + #[cfg(windows)] + { + use windows::{ + Win32::{ + System::Diagnostics::Debug::MessageBeep, + UI::WindowsAndMessaging::MB_ICONSTOP + } + }; + unsafe { + MessageBeep(MB_ICONSTOP.0); + } + } +} diff --git a/src-tauri/src/commands/preview_page.rs b/src-tauri/src/commands/preview_page.rs index a396333f..60c6a711 100644 --- a/src-tauri/src/commands/preview_page.rs +++ b/src-tauri/src/commands/preview_page.rs @@ -3,7 +3,7 @@ use std::thread::sleep; use std::time::Duration; use tauri::http::{Request, Response}; use tauri::{ - command, AppHandle, LogicalPosition, Manager, Window, WindowBuilder, WindowEvent, WindowUrl, + command, AppHandle, Manager, Window, WindowBuilder, WindowEvent, WindowUrl, }; use tracing::{info, instrument}; @@ -36,6 +36,7 @@ const INSERT: &str = r#" \ No newline at end of file diff --git a/src/components/SettingPage.vue b/src/components/SettingPage.vue index 09811b9d..cf9ac517 100644 --- a/src/components/SettingPage.vue +++ b/src/components/SettingPage.vue @@ -10,40 +10,50 @@ @click="setting.close" > - -
-
- 开机自启 - 每次开机就能自动蹲饼呢~ -
-
- -
-
-
- -
-
- 版本 - 当前版本 {{ setting.currentVersion }} -
-
- 检查更新 - - - - 弹窗 - -
-
-
+ + + + + + + + + + + + + + + 检测到了新版本,即将跳转到下载网页 @@ -55,22 +65,25 @@ diff --git a/src/view/Notification.vue b/src/view/Notification.vue index a38290ca..177d296c 100644 --- a/src/view/Notification.vue +++ b/src/view/Notification.vue @@ -2,15 +2,15 @@
@@ -34,7 +34,7 @@ import operate from "@/api/operations/operate"; import {appWindow} from "@tauri-apps/api/window"; const info = ref({ - setImg:false, + setImg: false, imgUrl: getImage("/assets/image/logo/icon.png"), dataSource: "", cookieTime: "", @@ -51,7 +51,7 @@ const updatePageData = (newData: Cookie) => { let images = newData.default_cookie.images; if (images) { - info.value.setImg=true; + info.value.setImg = true; if (newData.datasource.includes("微博")) { ceobeRequest .getHasRefererImageBase64(images[0].origin_url) @@ -64,29 +64,32 @@ const updatePageData = (newData: Cookie) => { } } else { console.log("no image"); - info.value.imgUrl=getImage("/assets/image/logo/icon.png") - info.value.setImg=false; + info.value.imgUrl = getImage("/assets/image/logo/icon.png") + info.value.setImg = false; } }; let unliten: UnlistenFn; onMounted(() => { - notification.getInfo((_, data) => { - operate.hideNotifyIcon() - console.log("get Info: " ,data) + notification.getInfo(async (_, data) => { + await operate.hideNotifyIcon() + console.log("get Info: ", data) updatePageData(data); - appWindow.show() - operate.messageBeep() + await appWindow.show() + if (await notification.needBeep()) { + + await operate.messageBeep() + } }).then((closer) => { unliten = closer }); }) onUnmounted(() => { -if (unliten){ - unliten() -} + if (unliten) { + unliten() + } }) function closeThis() { From 1c8e8dce86ff4b1000811be50189cf31c4190d65 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sat, 9 Sep 2023 21:21:19 +0800 Subject: [PATCH 13/34] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=84=8F?= =?UTF-8?q?=E5=A4=96=E5=88=A0=E9=99=A4=E7=9A=84=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SettingItem/SettingItem.vue | 3 ++- src/components/SettingPage.vue | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/SettingItem/SettingItem.vue b/src/components/SettingItem/SettingItem.vue index acc359fd..8620e965 100644 --- a/src/components/SettingItem/SettingItem.vue +++ b/src/components/SettingItem/SettingItem.vue @@ -12,7 +12,7 @@ const color = ref("#ffba4b")