Skip to content

Commit

Permalink
feat: 不使用磨砂窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Jun 13, 2024
1 parent f6ad09a commit 02e7edd
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 69 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ TODO:
- [ ] 贴边的剪切板窗口(卡在窗口无法在任务栏之上)
- [ ] 复制内容来源的应用信息(欢迎各位 rust 大佬指点)
- [ ] 快捷回复窗口
- [x] 兼容 Windows
1. - [x] 当前的 `createWindow` 函数在 Windows 系统有 bug(Rust `create_window` 方法必须是异步的)
2. - [x] `appWindow.onFocusChanged` 在 Windows 系统会频繁触发
3. - [x] ~~磨砂窗口在 Windows 各版本系统表现不一~~(参考其它软件的界面,为保持一致性,暂时不考虑做磨砂窗口)
4. - [x] 在 Rust 中使用除 Windows 系统以外生效的函数时不要直接导入,在使用时引入就好了
14 changes: 0 additions & 14 deletions src-tauri/Cargo.lock

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

1 change: 0 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ tauri = { version = "1", features = [ "system-tray", "macos-private-api", "api-a
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-clipboard = "0.6.10"
window-vibrancy = "0.4.3"
tauri-plugin-theme = "0.2.0"
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
Expand Down
7 changes: 1 addition & 6 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use tauri_plugin_theme::ThemePlugin;
mod tray;
mod window;
use tauri_plugin_autostart::MacosLauncher;
use window::{
create_window, frosted_window, hide_window, quit_app, set_window_shadow, show_window,
MAIN_WINDOW_LABEL,
};
use window::{create_window, hide_window, quit_app, show_window, MAIN_WINDOW_LABEL};

fn main() {
let mut ctx = generate_context!();
Expand Down Expand Up @@ -56,8 +53,6 @@ fn main() {
hide_window,
show_window,
quit_app,
frosted_window,
set_window_shadow
])
// 让 app 保持在后台运行:https://tauri.app/v1/guides/features/system-tray/#preventing-the-app-from-closing
.on_window_event(|event| match event.event() {
Expand Down
26 changes: 5 additions & 21 deletions src-tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ pub async fn create_window(app_handle: AppHandle, label: String, mut options: Wi
} else {
options.label = label.to_string();

WindowBuilder::from_config(&app_handle, options)
let window = WindowBuilder::from_config(&app_handle, options.clone())
.build()
.unwrap();

if !options.decorations {
window_shadows::set_shadow(&window, true).unwrap();
}
}
}

Expand All @@ -36,23 +40,3 @@ pub fn hide_window(window: Window) {
pub fn quit_app() {
std::process::exit(0)
}

// 磨砂窗口:https://github.com/tauri-apps/window-vibrancy
#[command]
pub fn frosted_window(_window: Window) {
#[cfg(target_os = "macos")]
window_vibrancy::apply_vibrancy(
&_window,
window_vibrancy::NSVisualEffectMaterial::HeaderView,
Some(window_vibrancy::NSVisualEffectState::Active),
Some(10.0),
)
.unwrap();
}

// 窗口阴影:https://github.com/tauri-apps/window-shadows
#[command]
pub fn set_window_shadow(_window: Window) {
#[cfg(target_os = "windows")]
window_shadows::set_shadow(&_window, true).unwrap();
}
2 changes: 1 addition & 1 deletion src/hooks/useListenClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useListenClipboard = (cb: Cb) => {
value = {
type: "files",
group: "files",
content: JSON.stringify(filesURIs.map(decodeURIComponent)),
content: JSON.stringify(filesURIs.map(decodeURI)),
};
} else if (updateTypes.image) {
value = {
Expand Down
1 change: 0 additions & 1 deletion src/pages/Clipboard/History/components/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const Popup = () => {

return (
<div
data-tauri-drag-region
style={{
...style,
top: Number(style.top) + (index - visibleStartIndex) * 12,
Expand Down
11 changes: 1 addition & 10 deletions src/pages/Clipboard/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Popup from "./components/Popup";

interface State extends HistoryItem {
historyList: HistoryItem[];
classNames?: string;
}

const INITIAL_STATE: State = {
Expand All @@ -34,14 +33,6 @@ const ClipboardHistory = () => {
const state = useReactive<State>(INITIAL_STATE);

useMount(async () => {
if (await isMac()) {
frostedWindow();
} else {
state.classNames = "bg-1";

setWindowShadow();
}

await initDatabase();

listen(LISTEN_KEY.CLEAR_HISTORY, async () => {
Expand Down Expand Up @@ -82,7 +73,7 @@ const ClipboardHistory = () => {
return (
<div
data-tauri-drag-region
className={clsx("h-screen p-12", state.classNames)}
className={clsx("h-screen rounded-10 bg-1 p-12")}
>
<audio ref={audioRef} src={copyAudio} />

Expand Down
10 changes: 0 additions & 10 deletions src/utils/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ export const showWindow = () => invoke("show_window");
*/
export const hideWindow = () => invoke("hide_window");

/**
* 磨砂窗口
*/
export const frostedWindow = () => invoke("frosted_window");

/**
* 退出 app
*/
Expand All @@ -53,8 +48,3 @@ export const toggleWindowVisible = async () => {
showWindow();
}
};

/**
* 设置窗口阴影
*/
export const setWindowShadow = () => invoke("set_window_shadow");

0 comments on commit 02e7edd

Please sign in to comment.