Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/noteiq-windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ windows = { version = "0.62", optional = true, features = [
"Data_Xml_Dom",
"Foundation",
"UI_Notifications",
"Win32_Storage_EnhancedStorage",
"Win32_System_Com_StructuredStorage",
"Win32_System_Variant",
"Win32_UI_Shell_PropertiesSystem",
"Win32_Foundation",
"Win32_Media_Audio",
"Win32_System_Com",
Expand Down
3 changes: 3 additions & 0 deletions apps/noteiq-windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ mod reminder;
#[cfg(windows)]
mod settings_ui;
#[cfg(windows)]
#[allow(unsafe_code)]
mod taskbar;
#[cfg(windows)]
mod toast;
#[cfg(windows)]
mod tray;
Expand Down
4 changes: 3 additions & 1 deletion apps/noteiq-windows/src/local_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ fn response_message(status: LanguageModelResponseStatus) -> &'static str {
LanguageModelResponseStatus::PromptLargerThanContext => {
"This note is too long for the on-device AI model."
}
// Windows detects the language itself and rejects short lowercase notes full of
// abbreviations, such as "deal alm closed", even when they are English.
LanguageModelResponseStatus::UnsupportedLanguage
| LanguageModelResponseStatus::LanguageMismatch => {
"The on-device AI model doesn't support this note's language."
"Windows couldn't recognize this note's language. Short notes with abbreviations often fail; try capitalizing names and acronyms or writing a full sentence."
}
LanguageModelResponseStatus::BlockedByPolicy => {
"Your organization's policy blocks the on-device AI model."
Expand Down
71 changes: 71 additions & 0 deletions apps/noteiq-windows/src/taskbar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! While NoteIQ has a package identity (needed for on-device AI), Windows groups its window
//! under the package and draws the taskbar button from the package logo, which shows as a blank
//! tile for a package with external location. Giving the window its own app ID makes the
//! taskbar use the window's icon again, as it does without the registration.

use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use windows::{
Win32::{
Foundation::{HWND, PROPERTYKEY},
Storage::EnhancedStorage::{
PKEY_AppUserModel_ID, PKEY_AppUserModel_RelaunchCommand,
PKEY_AppUserModel_RelaunchDisplayNameResource, PKEY_AppUserModel_RelaunchIconResource,
},
System::{
Com::StructuredStorage::{PROPVARIANT, PropVariantClear},
Variant::VT_LPWSTR,
},
UI::Shell::{
PropertiesSystem::{IPropertyStore, SHGetPropertyStoreForWindow},
SHStrDupW,
},
},
core::HSTRING,
};

/// Not registered anywhere, so the taskbar draws the window's own icon. The notification app
/// ID can't be reused: the taskbar would look up its registration instead.
const WINDOW_APP_ID: &str = "DevSecNinja.NoteIQ.Capture";

/// Best-effort: on failure the taskbar keeps the package's blank tile.
pub fn use_own_taskbar_identity(window: &impl HasWindowHandle) {
if windows::ApplicationModel::Package::Current().is_err() {
return;
}
let Ok(handle) = window.window_handle() else {
return;
};
let RawWindowHandle::Win32(handle) = handle.as_raw() else {
return;
};
let hwnd = HWND(handle.hwnd.get() as *mut core::ffi::c_void);
let executable = std::env::current_exe().unwrap_or_default();
let command = format!("\"{}\"", executable.display());
let icon = format!("{},0", executable.display());
// Pinning the button relaunches the executable, not the package.
let properties: [(&PROPERTYKEY, &str); 4] = [
(&PKEY_AppUserModel_RelaunchCommand, &command),
(&PKEY_AppUserModel_RelaunchDisplayNameResource, "NoteIQ"),
(&PKEY_AppUserModel_RelaunchIconResource, &icon),
(&PKEY_AppUserModel_ID, WINDOW_APP_ID),
];
// SAFETY: `hwnd` belongs to the live winit window on this UI thread. Each string is copied
// into COM memory by `SHStrDupW`, which `PropVariantClear` frees after `SetValue` copies it.
let result = unsafe {
SHGetPropertyStoreForWindow::<IPropertyStore>(hwnd).and_then(|store| {
for (key, value) in properties {
let mut variant = PROPVARIANT::default();
let inner = &mut *variant.Anonymous.Anonymous;
inner.Anonymous.pwszVal = SHStrDupW(&HSTRING::from(value))?;
inner.vt = VT_LPWSTR;
let set = store.SetValue(key, &variant);
PropVariantClear(&mut variant)?;
set?;
}
store.Commit()
})
};
if let Err(error) = result {
tracing::warn!(code = ?error.code(), "Could not give the window its own taskbar identity");
}
}
1 change: 1 addition & 0 deletions apps/noteiq-windows/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ pub fn run(
.await
.map_err(|_| "native_window_unavailable")?;
native.set_taskbar_icon(Some(icon));
crate::taskbar::use_own_taskbar_identity(&*native);
Ok::<_, &'static str>(())
}
.await;
Expand Down
5 changes: 4 additions & 1 deletion docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ Selecting the **Tidy up** toolbar button never changes the note directly:
OneDrive version history.

Only notes up to 700 characters can be tidied: in testing, longer notes were
more likely to have facts merged or changed. Windows may add an invisible
more likely to have facts merged or changed. Windows detects the note's language
itself and can reject very short lowercase notes full of abbreviations, such as
"deal alm closed", even when they are English; capitalizing names and acronyms or
writing a full sentence usually helps. Windows may add an invisible
AI-generated text marker (`U+200B U+034F U+2060 U+200B`) to the result; NoteIQ
keeps it and ignores it when comparing.

Expand Down