Skip to content

Commit

Permalink
enable click through overlay available on all platform, change github…
Browse files Browse the repository at this point in the history
… build action to build all os platform.
  • Loading branch information
SeakMengs committed Aug 11, 2023
1 parent 087c4b6 commit 4d5c2de
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 73 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
strategy:
fail-fast: false
matrix:
# platform: [macos-latest, ubuntu-latest, windows-latest]
platform: [windows-latest]
platform: [macos-latest, ubuntu-latest, windows-latest]
# platform: [windows-latest]
include:
# - os: ubuntu-latest
# rust_target: x86_64-unknown-linux-gnu
# - os: macos-latest
# rust_target: x86_64-apple-darwin
# - os: macos-latest
# rust_target: aarch64-apple-darwin
- os: ubuntu-latest
rust_target: x86_64-unknown-linux-gnu
- os: macos-latest
rust_target: x86_64-apple-darwin
- os: macos-latest
rust_target: aarch64-apple-darwin
- os: windows-latest
rust_target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.platform }}
Expand Down
1 change: 0 additions & 1 deletion src-tauri/Cargo.lock

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

10 changes: 1 addition & 9 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@ edition = "2021"
tauri-build = { version = "1.4", features = [] }

[dependencies]
tauri = { version = "1.4", features = [ "system-tray", "window-start-dragging", "shell-open"] }
tauri = { version = "1.4", features = [ "macos-private-api", "system-tray", "window-start-dragging", "shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }


[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

[dependencies.windows]
version = "0.48"
features = [
"Win32_Foundation",
"Win32_UI_WindowsAndMessaging",
]

[profile.release]
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
Expand Down
48 changes: 14 additions & 34 deletions src-tauri/src/app/utils.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
use tauri::{AppHandle, Window};

// click through window
// credit: https://github.com/4t145/tauri-windows-clickthrough-example
pub fn allow_window_click_through(window: Window, allow_click_through_window: bool) {
let hwnd = window.hwnd().unwrap().0;
let _pre_val;
let hwnd = windows::Win32::Foundation::HWND(hwnd);
unsafe {
use windows::Win32::UI::WindowsAndMessaging::*;
let nindex = GWL_EXSTYLE;
let style =
WS_EX_APPWINDOW | WS_EX_COMPOSITED | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST;

if allow_click_through_window {
_pre_val = SetWindowLongA(hwnd, nindex, style.0 as i32);
} else {
_pre_val = SetWindowLongA(hwnd, nindex, !style.0 as i32);
}
};
}
use tauri::AppHandle;

pub fn reopen_main_window(app: &AppHandle) {
let window = tauri::WindowBuilder::new(app, "main", tauri::WindowUrl::App("/".into()))
.fullscreen(true)
.resizable(false)
.transparent(true)
.decorations(false)
.always_on_top(true)
.title("WindowPet")
.skip_taskbar(true)
.build()
.unwrap();

allow_window_click_through(window, true);

// allow click through window
window
.set_ignore_cursor_events(true)
.unwrap_or_else(|err| println!("{:?}", err));

}

pub fn open_setting_window(app: &AppHandle) {
let _window = tauri::WindowBuilder::new(
app,
"setting",
tauri::WindowUrl::App("/setting".into()),
)
.title("WindowPet Setting")
.inner_size(800.0, 620.0)
.build()
.unwrap();
let _window =
tauri::WindowBuilder::new(app, "setting", tauri::WindowUrl::App("/setting".into()))
.title("WindowPet Setting")
.inner_size(800.0, 620.0)
.build()
.unwrap();
return;
}
}
7 changes: 4 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod app;

use app::cmd::{change_current_app_position, change_current_app_size};
use app::tray::{handle_tray_event, init_system_tray};
use app::utils::allow_window_click_through;
use tauri_plugin_autostart::MacosLauncher;

fn main() {
Expand All @@ -17,7 +15,10 @@ fn main() {
.setup(move |app| {
use tauri::Manager;
let window = app.get_window("main").unwrap();
allow_window_click_through(window, true);
window
.set_ignore_cursor_events(true)
.unwrap_or_else(|err| println!("{:?}", err));

Ok(())
})
.system_tray(init_system_tray())
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"width": 64,
"height": 64,
"transparent": true,
"decorations": false,
"alwaysOnTop": true,
"skipTaskbar": true
}
],
"systemTray": {
"iconPath": "icons/WindowPetNewTransparent.png",
"iconAsTemplate": true
}
},
"macOSPrivateApi": true
}
}
16 changes: 1 addition & 15 deletions src/components/setting_tabs/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useReducer } from "react";
import languages from "../../locale/languages";
import SettingSwitch from "./settings/SettingSwitch";
import { useTranslation } from "react-i18next";
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api";
import { isEnabled } from "tauri-plugin-autostart-api";
import { settingReducer } from "../../hooks/settingReducer";

interface settingsProp {
Expand Down Expand Up @@ -47,20 +47,6 @@ function Settings() {
})
};

useEffect(() => {
if (state.autoStartUp) {
async function enableAutoStartUp() {
await enable();
}
enableAutoStartUp();
} else {
async function disableAutoStartUp() {
await disable();
}
disableAutoStartUp();
}
}, [state.autoStartUp]);

useEffect(() => {
i18n.changeLanguage(state.language as string);
}, [state.language]);
Expand Down
9 changes: 8 additions & 1 deletion src/hooks/settingReducer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
toggleAutoStartUp,
} from "../utils/settingsFunction";

interface State {
language: string;
autoStartUp: boolean;
Expand All @@ -16,9 +20,12 @@ export const settingReducer = (state: State, action: Action) => {
language: action.payload.value
}
case 'switchAutoWindowStartUp':
const isAutoStartUp: boolean = action.payload.value
toggleAutoStartUp(isAutoStartUp);

return {
...state,
autoStartUp: action.payload.value
autoStartUp: isAutoStartUp
}
default:
return state
Expand Down
15 changes: 15 additions & 0 deletions src/utils/settingsFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { enable, isEnabled, disable } from "tauri-plugin-autostart-api";

export async function toggleAutoStartUp(isAutoStartUp: boolean) {
const hasEnabledStartUp = await isEnabled();

if (isAutoStartUp) {
if (hasEnabledStartUp) return;
await enable();
return;
}

if (hasEnabledStartUp) {
await disable();
}
};

0 comments on commit 4d5c2de

Please sign in to comment.