Skip to content

Commit

Permalink
Merge branch 'release_tauri' into release_tauri-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodjooy authored Oct 2, 2023
2 parents 8d43c35 + 4a89151 commit 5a9fa0d
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 299 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">

![LOGO](src-tauri/icons/128x128.png)
[![LOGO](src-tauri/icons/128x128.png)](https://ceobecanteen.top/)

帮小刻找好多好吃的饼

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "ceobe-canteen-desktop"
version = "1.0.0-rc2"
description = "小刻食堂的桌面端,恭喜你电脑有多了个和小刻一样喜欢吃东西的浏览器内核 "
authors = ["FrozenString<frozenstringstable@gmail.com>"]
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"
Expand All @@ -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"
Expand Down Expand Up @@ -60,3 +60,8 @@ features = ["Data_Xml_Dom",
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

[profile.release]
opt-level="s"
strip = true
lto = true
30 changes: 30 additions & 0 deletions src-tauri/assets/user-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
《产品声明》
本产品为非商业化产品,除捐助用于服务器运行资金外无任何收益。

本产品仅供学习交流使用。

本产品相关内容(文字、图片、音视频等)均来源于/转自第三方,平台转载相关内容不视为对于相关内容、观点的认可,亦不视为对于相关内容的真实性、准确性、完整性、合法性做出任何承诺。相关内容的真实合法性由内容发布者自行承担,本平台不承担相关法律责任。本平台已明确提示内容来源,如相关内容侵犯了您的合法权益,您亦需联系发布源进行处理。

来自于第三方网站的链接,系由平台根据您的搜索需求或为向您提供便利而提供或设置,外部链接指向的不由本平台实际控制的任何网页上的内容,本平台不承担任何责任。您可能从该第三方网站上获得资讯及享用服务,本平台网无法控制第三方提供的内容、服务的质量、安全或合法性、信息的真实性或准确性。您应自行谨慎判断确定,并自行承担因此产生的责任与损失。除非本平台另有明确规定,若您对于第三方网站或链接有任何异议,您应联系第三方网站的内容或链接提供者处理。

如若侵犯第三方权益,请您及时与我们联系,我们将立刻整改。


《用户守则》
欢迎使用由小刻食堂开发团队(以下简称「开发组」)开发的「小刻食堂」系列。在您使用本框架之前,请仔细阅读并完全理解本声明。一旦您开始使用小刻食堂,即表示您同意遵守本声明中的所有条款和条件。

1. 使用目的: 小刻食堂是一个免费开源的软件项目,旨在为用户提供抓取B站、微博、明日方舟通讯组等API数据的功能,并提供多种实用功能,如实时饼消息通知、快速跳转链接、饼内容分享、详细内容查看、饼内容图片生成、理智回复时间计算等。

2. 合法合理使用: 您承诺以合法、合理的方式使用小刻食堂,不得将其用于任何违法、侵权或其他恶意行为,也不得将其应用于违反当地法律法规的Web平台。

3. 免责声明: 开发组对于因使用小刻食堂而引起的任何意外、疏忽、合同损害、诽谤、版权或知识产权侵权以及由此产生的损失(包括但不限于直接、间接、附带或衍生的损失等)不承担任何法律责任。

4. 风险承担: 用户明确同意,使用小刻食堂所存在的风险和后果将完全由用户自行承担,开发组不承担任何法律责任。

5. 合法发布和使用: 用户在遵守本声明的前提下,可在《MIT开源许可证》所允许的范围内合法地发布、传播和使用小刻食堂。对于因违反本声明或法律法规造成的法律责任(包括但不限于民事赔偿和刑事责任),将由违约者自行承担。

6. 知识产权: 小刻食堂及其相关产品享有开发组的知识产权保护,包括但不限于商标权、专利权、著作权、商业秘密等,受相关法律法规保护。

7. 条款变更: 开发组有权随时单方面修改本声明条款及附件内容,并通过消息推送、网页公告等方式进行公布。变更后的条款在公布后立即生效,用户继续使用即表示您已充分阅读、理解并接受修改后的声明内容。

请在使用小刻食堂之前仔细阅读并理解本声明。如果您有任何疑问,请咨询相关法律专业人士。感谢您的合作与支持!
35 changes: 35 additions & 0 deletions src-tauri/src/commands/front_logger.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
22 changes: 22 additions & 0 deletions src-tauri/src/commands/hide_notification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use tauri::{command, Window};

#[command]
pub fn hide_notification(window: Window) -> tauri::Result<()> {
#[cfg(windows)]
{
use windows::Win32::Graphics::Gdi::UpdateWindow;
use windows::Win32::UI::WindowsAndMessaging::{
GetWindowLongPtrW, SetWindowLongPtrW, GWL_EXSTYLE, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW,
};
let hwnd = window.hwnd()?;
let mut style = unsafe { GetWindowLongPtrW(hwnd, GWL_EXSTYLE) };
style |= !WS_EX_APPWINDOW.0 as isize;
style &= WS_EX_TOOLWINDOW.0 as isize;
unsafe { SetWindowLongPtrW(hwnd, GWL_EXSTYLE, style) };
unsafe {
UpdateWindow(hwnd);
}
}

Ok(())
}
6 changes: 6 additions & 0 deletions src-tauri/src/commands/is_debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use tauri::command;

#[command]
pub fn is_debug() -> bool {
cfg!(debug_assertions)
}
10 changes: 10 additions & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
mod auto_launch;
mod clipboard;
mod front_logger;
mod hide_notification;
mod is_debug;
mod local_storage;
mod monitor_info;
mod preview_page;
mod quit;
mod request_client;
mod request_refer_image;
mod resource_location;
mod update_available;

pub use self::auto_launch::{auto_launch_setting, set_auto_launch};
pub use clipboard::copy_image;
pub use front_logger::front_logger;
pub use hide_notification::hide_notification;
pub use is_debug::is_debug;
pub use local_storage::{get_item, set_item};
pub use monitor_info::{get_monitor_info, message_beep};
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 resource_location::{get_app_cache_path, get_app_config_path};
64 changes: 64 additions & 0 deletions src-tauri/src/commands/monitor_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use serde::Serialize;

use tauri::{command, PhysicalPosition, PhysicalSize, Window};

#[derive(Debug, Clone, Serialize)]
pub struct MonitorInfo {
work_space: PhysicalSize<u32>,
left_top: PhysicalPosition<i32>,
}

#[command]
pub fn get_monitor_info(window: Window) -> tauri::Result<MonitorInfo> {
#[cfg(not(windows))]
{
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::<MONITORINFO>() 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);
}
}
}
5 changes: 2 additions & 3 deletions src-tauri/src/commands/preview_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use reqwest::Url;
use std::thread::sleep;
use std::time::Duration;
use tauri::http::{Request, Response};
use tauri::{
command, AppHandle, LogicalPosition, Manager, Window, WindowBuilder, WindowEvent, WindowUrl,
};
use tauri::{command, AppHandle, Manager, Window, WindowBuilder, WindowEvent, WindowUrl};
use tracing::{info, instrument};

const WINDOWS_NAME: &str = "Preview";
Expand Down Expand Up @@ -36,6 +34,7 @@ const INSERT: &str = r#"<style type="text/css">
#[instrument(skip_all, err, name = "LeavePreview")]
pub fn back_preview(app: AppHandle) -> tauri::Result<()> {
if let Some(win) = app.get_window(WINDOWS_NAME) {
win.eval("window.location.replace('about:black')")?;
win.hide()?;
}
Ok(())
Expand Down
12 changes: 12 additions & 0 deletions src-tauri/src/commands/resource_location.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::state::{get_cache_dir, get_config_dir};
use std::path::PathBuf;
use tauri::{command, AppHandle};

#[command]
pub fn get_app_config_path(app: AppHandle) -> PathBuf {
get_config_dir(app).to_owned()
}
#[command]
pub fn get_app_cache_path(app: AppHandle) -> PathBuf {
get_cache_dir(app).to_owned()
}
14 changes: 11 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use tauri::api::path::app_log_dir;
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,
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, set_auto_launch, set_item,
};
use crate::setup::logger::init_logger;
use crate::setup::system_tray::new_system_tray;
Expand Down Expand Up @@ -60,7 +61,14 @@ fn main() {
set_item,
send_request,
quit,
back_preview
back_preview,
front_logger,
get_monitor_info,
message_beep,
get_app_cache_path,
get_app_config_path,
hide_notification,
is_debug
]);

let app = builder
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/request_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use http::Method;
use http_cache_reqwest::{Cache, CacheMode, HttpCache, HttpCacheOptions};
use reqwest::{Client, IntoUrl, Request, Response};
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, RequestBuilder};
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::RetryTransientMiddleware;
use std::sync::OnceLock;
use std::time::Duration;
use reqwest_retry::policies::{ExponentialBackoff};
use reqwest_retry::RetryTransientMiddleware;
use tauri::AppHandle;
use tracing::{info, instrument, Level};

Expand All @@ -30,7 +30,7 @@ impl RequestClient {
let cache_location = get_cache_dir(app).join(HTTP_CACHE);
let retry_policy = ExponentialBackoff::builder()
.backoff_exponent(2)
.retry_bounds(Duration::from_millis(500),Duration::from_secs(16))
.retry_bounds(Duration::from_millis(500), Duration::from_secs(16))
.build_with_total_retry_duration(Duration::from_secs(120));
info!(firstInit="RequestClient",cacheLocal = ?cache_location);
let client = ClientBuilder::new(Client::new())
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/setup/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs::{File, OpenOptions};
use std::io;
use std::io::{stdout, IoSlice, Write};
use std::ops::Deref;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use tracing::level_filters::LevelFilter;
use tracing::{info, Subscriber};
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a> MakeWriter<'a> for LogWriter {
}

impl LogWriter {
fn open_log_file(path: &PathBuf) -> io::Result<File> {
fn open_log_file(path: &Path) -> io::Result<File> {
let now = Local::now();
let format = now.format("%Y-%m-%dT%H-%M-%S");
let filename = format!("log-{format}.log");
Expand Down
Loading

0 comments on commit 5a9fa0d

Please sign in to comment.