Skip to content

Commit

Permalink
chore: 修复windows平台错误
Browse files Browse the repository at this point in the history
  • Loading branch information
lly-ke committed Jan 18, 2023
1 parent 58c502c commit 8de7673
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 85 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changelog

## 2023.1.15
## 23.1.15 (2023.01.15)

初始化f-t
第一个版本, 完成基本功能
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>f-t</title>
</head>
<body>
<div id="app"></div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "f-t",
"private": true,
"version": "2023.1.15",
"version": "23.1.15",
"author": {
"name": "lly ke",
"email": "2720851545@qq.com"
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.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "f-t"
version = "2023.1.15"
version = "23.1.15"
description = "A Tauri App"
authors = ["lly ke"]
license = "MIT"
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::setup::set_window_vibrancy;

#[tauri::command]
pub fn backend_add(number: i32) -> i32 {
// Note: these commands block the main thread and hang the UI until they return.
// If you need to run a long-running task, use async command instead.
println!("Backend was called with an argument: {}", number);
// set_window_vibrancy();
number + 2
}
74 changes: 2 additions & 72 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,13 @@
windows_subsystem = "windows"
)]

use tauri::utils::assets::EmbeddedAssets;
use tauri::api::shell;
use tauri::{App, CustomMenuItem, GlobalShortcutManager, Manager, Menu, MenuItem, Submenu, Wry, Context, AboutMetadata};
mod setup;

#[tauri::command]
fn backend_add(number: i32) -> i32 {
// Note: these commands block the main thread and hang the UI until they return.
// If you need to run a long-running task, use async command instead.
println!("Backend was called with an argument: {}", number);
number + 2
}

// fn register_shortcut(app: &App<Wry>) {
// let mut short_cut = app.global_shortcut_manager(); //获取快捷键管理实例
// let app_handler = app.handle();
// let result = short_cut.register("command+w", move || {
// let window = app_handler.get_window("main").unwrap();
// window.close();
// });
// if let Err(err) = result {
// println!("{}", err);
// }
// }

pub fn init(context: &Context<EmbeddedAssets>) -> Menu {
// 应用名称
let name = &context.package_info().name;
// tauri::Menu::os_default(name)
// 应用主菜单
let app_menu = Submenu::new(
"",
// MenuItem::About 为原生菜单
Menu::new().add_native_item(MenuItem::About(name.into(), AboutMetadata::new())),
);
// 文件菜单(自定义菜单)
let file_menu = Submenu::new(
"File",
Menu::new()
.add_item(CustomMenuItem::new("new_file".to_string(), "New File"))
.add_item(CustomMenuItem::new("edit_file".to_string(), "Edit File")),
);
// 编辑菜单(自定义菜单)
let edit_menu = Submenu::new(
"Edit",
Menu::new()
.add_item(CustomMenuItem::new("undo".to_string(), "Undo"))
.add_item(CustomMenuItem::new("redo".to_string(), "Redo")),
);

Menu::new()
.add_submenu(app_menu)
.add_submenu(file_menu)
.add_submenu(edit_menu)
}
mod commands;

fn main() {
let ctx = tauri::generate_context!();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![backend_add])
// .menu(Menu::with_items([
// MenuItem::SelectAll.into(),
// MenuItem::Redo.into(),
// CustomMenuItem::new("toggle", "Toggle visibility").into(),
// Submenu::new("View", Menu::new()).into(),
// ]))
.menu(init(&ctx))
.on_menu_event(|event| {
let event_name = event.menu_item_id();
match event_name {
"Online Documentation" => {
let url = "https://github.com/Uninen/tauri-vue-template".to_string();
shell::open(&event.window().shell_scope(), url, None).unwrap();
}
_ => {}
}
})
.invoke_handler(tauri::generate_handler![commands::backend_add])
.setup(setup::init)
.run(ctx)
.expect("error while running tauri application");
Expand Down
17 changes: 11 additions & 6 deletions src-tauri/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
use tauri::{App, Manager};
use tauri::{App, Manager, Window};
use window_vibrancy::{self, NSVisualEffectMaterial, NSVisualEffectState};

/// setup
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {
let win = app.get_window("main").unwrap();
set_window_vibrancy(win);
Ok(())
}

pub fn set_window_vibrancy(win: Window) {
// 仅在 macOS 下执行
#[cfg(target_os = "macos")]
window_vibrancy::apply_vibrancy(
&win,
NSVisualEffectMaterial::FullScreenUI,
Some(NSVisualEffectState::FollowsWindowActiveState),
Some(12.1)
Some(12.1),
)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

// 仅在 windows 下执行
#[cfg(target_os = "windows")]
window_vibrancy::apply_blur(&win, Some((18, 18, 18, 125)))
.expect("Unsupported platform! 'apply_blur' is only supported on Windows");

Ok(())
// 支持win10和win11
window_vibrancy::apply_acrylic(&win, Some((18, 18, 18, 125)))
.expect("Unsupported platform! 'apply_acrylic' is only supported on Windows");
// 只支持win11
// window_vibrancy::apply_mica(&win);
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "f-t",
"version": "2023.1.15"
"version": "23.1.15"
},
"build": {
"distDir": "../dist",
Expand Down

0 comments on commit 8de7673

Please sign in to comment.