Skip to content

Commit ac5aec9

Browse files
committed
fix(tray): tray hook not loading on msix
1 parent 13ed174 commit ac5aec9

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

.cert/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ your system to trust nighly msix packages.
1717
4. Run the following command
1818

1919
```pwsh
20-
$password = ConvertTo-SecureString -String seelen -Force -AsPlainText
20+
$password = ConvertTo-SecureString -String Seelen -Force -AsPlainText
2121
Import-PfxCertificate -FilePath .\Seelen.pfx -CertStoreLocation Cert:\LocalMachine\root -Password $password
2222
```
2323

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [2.4.11]
44

5+
### fix
6+
7+
- tray not working on MSIX installation.
8+
59
## [2.4.10]
610

711
### refactor

scripts/bundle.msix.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ fs.copyFileSync(`target/${target}/release/seelen-ui.exe`, `${buildFolder}/seelen
5757
fs.copyFileSync(`target/${target}/release/slu-service.exe`, `${buildFolder}/slu-service.exe`);
5858
fs.copyFileSync(`target/${target}/release/splash.exe`, `${buildFolder}/splash.exe`);
5959

60+
// add pdb files if debug
61+
if (pre || target === "./") {
62+
fs.copyFileSync(`target/${target}/release/seelen_ui.pdb`, `${buildFolder}/seelen_ui.pdb`);
63+
}
64+
6065
// dlls
6166
fs.copyFileSync(`target/${target}/release/sluhk.dll`, `${buildFolder}/sluhk.dll`);
6267

src/background/modules/system_tray/application/tray_hook_loader.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use windows::{
1010
};
1111

1212
use crate::{
13-
error::ResultLogExt, modules::system_tray::application::util::Util, windows_api::WindowsApi,
13+
error::{Result, ResultLogExt},
14+
modules::system_tray::application::util::Util,
15+
utils::constants::SEELEN_COMMON,
16+
windows_api::WindowsApi,
1417
};
1518

1619
// ============================================================================
@@ -37,7 +40,7 @@ pub struct TrayHookLoader {
3740
impl TrayHookLoader {
3841
/// Creates a new loader, loads the DLL and installs the hook
3942
/// Events will be sent automatically through AppIpc
40-
pub fn new() -> crate::Result<Self> {
43+
pub fn new() -> Result<Self> {
4144
let dll_path = Self::get_dll_path()?;
4245
let dll_handle = Self::load_dll(&dll_path)?;
4346
let call_msg_proc = Self::get_proc_address::<GetMsgProcFn>(dll_handle, "CallWndProc")?;
@@ -65,25 +68,41 @@ impl TrayHookLoader {
6568
})
6669
}
6770

68-
/// Gets the DLL path
69-
fn get_dll_path() -> crate::Result<PathBuf> {
71+
/// Gets the DLL path, copying it to SEELEN_COMMON temp directory to avoid
72+
/// permission issues with MSIX installations (WindowsApps folder is restricted)
73+
fn get_dll_path() -> Result<PathBuf> {
7074
let exe_path = std::env::current_exe()?;
7175
let exe_dir = exe_path
7276
.parent()
7377
.ok_or("Failed to get executable directory")?;
7478

7579
// The DLL should be in the same directory as the executable
76-
let dll_path = exe_dir.join("sluhk.dll");
77-
78-
if !dll_path.exists() {
79-
return Err(format!("DLL not found at: {}", dll_path.display()).into());
80+
let source_dll_path = exe_dir.join("sluhk.dll");
81+
if !source_dll_path.exists() {
82+
return Err(format!("DLL not found at: {}", source_dll_path.display()).into());
8083
}
8184

82-
Ok(dll_path)
85+
// Copy to temp directory to ensure accessibility for hooks
86+
// (MSIX installations in WindowsApps have restricted permissions)
87+
let temp_dir = SEELEN_COMMON.app_temp_dir();
88+
std::fs::create_dir_all(temp_dir)?;
89+
let target_dll_path = temp_dir.join("sluhk.dll");
90+
91+
// Use read & write instead of copy to avoid encryption issues on MSIX/APPX
92+
// when copying across different volumes (e.g., S: to C:)
93+
let content = std::fs::read(&source_dll_path)?;
94+
std::fs::write(&target_dll_path, content)?;
95+
log::info!(
96+
"Tray hook DLL copied from {} to {}",
97+
source_dll_path.display(),
98+
target_dll_path.display()
99+
);
100+
101+
Ok(target_dll_path)
83102
}
84103

85104
/// Loads the DLL into memory
86-
fn load_dll(path: &Path) -> crate::Result<HMODULE> {
105+
fn load_dll(path: &Path) -> Result<HMODULE> {
87106
let path_wide: Vec<u16> = path
88107
.to_string_lossy()
89108
.encode_utf16()
@@ -97,7 +116,7 @@ impl TrayHookLoader {
97116
}
98117

99118
/// Gets the address of an exported function
100-
fn get_proc_address<F>(dll_handle: HMODULE, name: &str) -> crate::Result<F> {
119+
fn get_proc_address<F>(dll_handle: HMODULE, name: &str) -> Result<F> {
101120
let name_cstr = std::ffi::CString::new(name)
102121
.map_err(|e| format!("Invalid function name '{}': {}", name, e))?;
103122

src/tauri.conf.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"**/*.png",
1818
"**/*.webp",
1919
"**/*.gif",
20-
"**/*.mp4",
21-
"**/*.mkv",
22-
"**/*.wav"
20+
"**/*.svg"
2321
]
2422
}
2523
},

0 commit comments

Comments
 (0)