diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a72e0..e6b0056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to MagicInput are documented here. The project follows [Semantic Versioning](https://semver.org). +## [Unreleased] + +### Added + +- **Update notice.** When a newer version is out, the panel says so with a Download button, and the menu bar / tray menu shows "Update to …". The panel asks GitHub for the latest version number when it opens (and once a day while the icon is on); nothing about your computer is sent. Turn it off with `check_updates = false` in the config file. Microsoft Store installs don't check, since the Store updates them. +- **Report a problem**, in the panel's footer and the icon's menu, opens a GitHub bug report with your MagicInput and system versions filled in. + ## [0.6.2] - 2026-10-25 ### Changed diff --git a/PRICING.md b/PRICING.md index 47a7450..b39628e 100644 --- a/PRICING.md +++ b/PRICING.md @@ -18,7 +18,7 @@ Free for personal use also covers schools, charities, public research and govern - **Read or audit the code.** The full source is public, every release is built from it, and independent security reviews are welcome. Report findings privately as described in [SECURITY.md](SECURITY.md). - **Verify your download.** Each [release](https://github.com/betoxf/Magicinput/releases) publishes `SHA256SUMS.txt`, so you can confirm the file you downloaded is the one released (`shasum -a 256 MagicInput.dmg`). The Mac app and disk image are signed with an Apple Developer ID and notarized by Apple (`spctl --assess --verbose /Applications/MagicInput.app`). -- **Watch what it does.** No accounts, no telemetry: MagicInput only talks to your other computer on your local network (and, with a monthly or yearly business key, renews it once a day), which you can confirm with any network monitor. +- **Watch what it does.** No accounts, no telemetry: MagicInput only talks to your other computer on your local network, apart from asking GitHub for the latest version number when the settings panel opens (`check_updates = false` turns that off) and, with a monthly or yearly business key, renewing it once a day. You can confirm this with any network monitor. ## Licenses diff --git a/README.md b/README.md index d87b9a6..76f808d 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Yes. Copied text goes with the pointer to the other computer, and ⌘C / ⌘V wo ### Is it secure? Does it need the internet or an account? -No internet, no account, no cloud. The two computers talk only on your local network, encrypted end to end with your pairing code. Connections from outside your network are refused. See [Privacy and security](#privacy-and-security). +It doesn't need the internet, an account or a cloud. The two computers talk only on your local network, encrypted end to end with your pairing code. Connections from outside your network are refused. If the internet is there, the settings panel asks GitHub whether a newer version is out (you can turn that off). See [Privacy and security](#privacy-and-security). ### Does it work on Linux, or with more than two computers? @@ -202,7 +202,7 @@ Not yet. MagicInput is for one Mac and one Windows PC (Windows 10 or 11, macOS 1 ## Privacy and security - Input, clipboard text and settings travel only between your two computers, encrypted. -- MagicInput has no servers, no account and no telemetry. With a monthly or yearly license, it fetches a fresh key from bullfighterstudio.com about once a day; that's the only server it talks to. +- MagicInput has no servers, no account and no telemetry. The settings panel asks GitHub which version is the latest release when it opens (and once a day while the menu bar / tray icon is on), so it can say when an update is out; the request carries nothing about you or your computers. Turn it off with `check_updates = false` in the config file. With a monthly or yearly license, it also fetches a fresh key from bullfighterstudio.com about once a day. Those are the only servers it talks to. - Nothing is accepted from outside your local network. - The macOS permissions (Accessibility, Input Monitoring) are what any keyboard/mouse sharing tool needs to see and send input. - The source code is public, so you or your security team can audit exactly what it does, and check the downloads against the published checksums ([how](PRICING.md#check-it-yourself)). diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 380a628..e34c803 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -54,7 +54,7 @@ Bursts of movement are merged before sending. On the receiving side, movement th ## Settings panel -A borderless window with system glass (vibrancy on macOS, acrylic on Windows) hosting a small web page (`src/ui.html`). It is shown only once drawn, attaches under the tray icon, closes on click-away or Esc, and is kept hidden for reuse while the icon is on. On macOS the menu bar icon is a live vector image composed from SF Symbols; display names and wallpapers come from AppKit, and displays are moved with Core Graphics display configuration. +A borderless window with system glass (vibrancy on macOS, acrylic on Windows) hosting a small web page (`src/ui.html`). It is shown only once drawn, attaches under the tray icon, closes on click-away or Esc, and is kept hidden for reuse while the icon is on. When it starts, and once a day while it keeps running for the icon, the panel reads which version GitHub's latest-release page redirects to (`curl`, nothing sent about the computer) and offers the download if it's newer; `check_updates = false` turns that off, and Store installs skip it. "Report a problem" (footer and icon menu) opens a GitHub bug report with the MagicInput and system versions filled in. On macOS the menu bar icon is a live vector image composed from SF Symbols; display names and wallpapers come from AppKit, and displays are moved with Core Graphics display configuration. ## Footprint diff --git a/src/config.rs b/src/config.rs index 353e2d7..6bc4410 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,6 +82,9 @@ pub struct Config { pub license: String, /// When a subscription key was last refreshed (unix seconds). pub license_checked: u64, + /// The settings panel asks GitHub whether a newer version is out and says so (it sends + /// nothing about this computer). `false` turns that off. + pub check_updates: bool, } impl Default for Config { @@ -105,6 +108,7 @@ impl Default for Config { layout_time: 0, license: String::new(), license_checked: 0, + check_updates: true, } } } diff --git a/src/lib.rs b/src/lib.rs index 069c8c6..55b0c59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ mod proto; mod service; mod status; pub mod ui; +mod update; use std::io::IsTerminal; diff --git a/src/license.rs b/src/license.rs index 46351fd..e1d45df 100644 --- a/src/license.rs +++ b/src/license.rs @@ -65,7 +65,8 @@ pub fn due(cfg: &Config) -> bool { } /// Fetch a fresh key for a subscription from bullfighterstudio.com, so it keeps working after each -/// renewal. This is the only time MagicInput contacts a server, and only once a key is entered. +/// renewal. Apart from the settings panel's check for a new version (`crate::update`), this is the +/// only time MagicInput contacts a server, and only once a key is entered. pub fn refresh(cfg: &Config) -> Option { let session = decode(&cfg.license)?.s?; if !session.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { diff --git a/src/ui.html b/src/ui.html index 27b2623..d4b2496 100644 --- a/src/ui.html +++ b/src/ui.html @@ -154,6 +154,10 @@ footer { text-align: center; color: var(--faint); font-size: 10.5px; padding: 10px 0 0; } footer a { color: var(--muted); text-decoration: none; cursor: default; } footer a:hover { color: var(--text); } + footer div + div { margin-top: 2px; } + .update { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 8px 8px 12px; } + .update[hidden] { display: none; } + .update .grow { flex: 1; font-size: 12px; font-weight: 500; } @@ -204,7 +208,12 @@

MagicInput

- + + +
@@ -251,7 +260,7 @@

MagicInput

pc: '', }; const esc = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); - let S = null, walls = {}, ready = false; + let S = null, walls = {}, ready = false, sent = 0; $('power').onclick = () => send('login', !S?.login); $('auto').onclick = () => send('auto'); @@ -270,6 +279,7 @@

MagicInput

$('scrim').onclick = () => { pairing(false); licensing(false); }; const PHINT = 'One license covers all your computers.'; $('buy').onclick = () => send('buy'); + $('updateBtn').onclick = () => send('update'); $('licInput').oninput = () => { $('activate').disabled = !$('licInput').value.includes('.'); $('pHint').textContent = PHINT; }; $('activate').onclick = () => send('license', $('licInput').value); $('licInput').onkeydown = e => { if (e.key === 'Enter' && !$('activate').disabled) $('activate').click(); }; @@ -455,8 +465,13 @@

MagicInput

// Licensing (footer link and sheet): free for personal use, a key for businesses. const plan = { monthly: 'Monthly', yearly: 'Yearly', lifetime: 'Lifetime' }[s.license] || s.license; const label = s.license ? 'Business license' : 'Free for personal use'; - $('escHint').innerHTML = esc((mac ? '⌃⌥Esc' : 'Ctrl+Alt+Esc') + ' brings the pointer home') + ' · ' + esc(label) + ''; + $('escHint').textContent = (mac ? '⌃⌥Esc' : 'Ctrl+Alt+Esc') + ' brings the pointer home'; + $('links').innerHTML = '' + esc(label) + ' · Report a problem'; $('plink').onclick = () => licensing(true); + $('rlink').onclick = () => send('report'); + // A newer version is out: say so above the footer. + $('update').hidden = !s.update; + if (s.update) $('updateText').textContent = 'MagicInput ' + s.update + ' is available'; $('pState').textContent = s.license ? 'Business license · ' + plan : 'Free for personal use'; $('pDesc').textContent = s.license ? 'Active on this computer. Thank you for supporting MagicInput.' @@ -465,12 +480,13 @@

MagicInput

if (!$('licInput').value) $('pHint').textContent = PHINT + ' v' + s.version; // First paint done: tell the app our height so it can attach and show the panel, then fade in. + if (ready && sent && $('panel').offsetHeight !== sent) send('resize', sent = $('panel').offsetHeight); if (!ready) { ready = true; // Measure once fonts are in (they change the height). Timers, not animation frames: the // window is still hidden, so frames don't run yet. document.fonts.ready.then(() => setTimeout(() => { - send('ready', $('panel').offsetHeight); + send('ready', sent = $('panel').offsetHeight); setTimeout(() => $('panel').classList.add('in'), 40); }, 0)); } diff --git a/src/ui.rs b/src/ui.rs index ed7e7fe..fde6477 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -21,7 +21,7 @@ use wry::{WebView, WebViewBuilder}; use crate::config::{self, Config, Layout}; use crate::geom::{self, Placement, Rect}; use crate::proto::Side; -use crate::{platform, service, status}; +use crate::{platform, service, status, update}; /// Local port a running window listens on, so opening the app again just brings it forward. const UI_PORT: u16 = 24843; @@ -42,11 +42,15 @@ enum UserEvent { Tick, /// Start-at-login finished changing (it can take a moment, or an admin prompt on Windows). LoginChanged, + /// A newer version is out. + Update(String), } struct Tray { _icon: TrayIcon, + menu: Menu, status: MenuItem, + update: Option, } /// Start the settings window in its own process (at login only the icon, if it's turned on). @@ -138,6 +142,33 @@ pub fn run(background: bool) { } }); } + // Look for a new version when the panel starts, then about once a day while it's kept running + // for the icon (by the clock, so sleep doesn't push it back), trying again each hour while + // offline. Store installs are updated by the Store. + #[cfg(windows)] + let store = crate::packaged(); + #[cfg(not(windows))] + let store = false; + if cfg.check_updates && !store { + let p = proxy.clone(); + std::thread::spawn(move || { + let mut checked = 0; + loop { + let now = crate::license::now(); + if now.saturating_sub(checked) >= 24 * 3600 + && let Some(found) = update::check() + { + checked = now; + if let Some(v) = found + && p.send_event(UserEvent::Update(v)).is_err() + { + return; + } + } + std::thread::sleep(Duration::from_secs(3600)); + } + }); + } // First time on this computer: start the background service right away. if !background && !service::installed() { @@ -155,6 +186,8 @@ pub fn run(background: bool) { // The current panel has finished loading once (so it can be re-shown as is). let mut loaded = false; let mut closed_at = std::time::Instant::now() - Duration::from_secs(5); + // A newer version, if one is out. + let mut newer: Option = None; event_loop.run(move |event, target, flow| { *flow = ControlFlow::Wait; @@ -164,7 +197,7 @@ pub fn run(background: bool) { match event { Event::NewEvents(StartCause::Init) => { if Config::load().show_tray { - tray = make_tray(); + tray = make_tray(&newer); } show = !background; opened = !background; @@ -196,9 +229,20 @@ pub fn run(background: bool) { save(|c| c.show_tray = false); tray = None; } + "report" => open_url(&update::report_url()), + "update" => open_url(update::RELEASES_URL), _ => {} }, Event::UserEvent(UserEvent::LoginChanged) => login = service::installed(), + Event::UserEvent(UserEvent::Update(v)) => { + if let Some(t) = &mut tray { + show_update(t, &v); + } + newer = Some(v); + if let Some((_, wv)) = &win { + let _ = wv.evaluate_script(&format!("render({})", state(&status::read(), login, &names, &newer))); + } + } Event::UserEvent(UserEvent::Tick) => { let st = status::read(); if let Some(t) = &tray { @@ -206,7 +250,7 @@ pub fn run(background: bool) { } if let Some((_, wv)) = &win { names = monitor_names(target); - let _ = wv.evaluate_script(&format!("render({})", state(&st, login, &names))); + let _ = wv.evaluate_script(&format!("render({})", state(&st, login, &names, &newer))); } } Event::UserEvent(UserEvent::Ipc(msg)) => { @@ -228,7 +272,7 @@ pub fn run(background: bool) { "tray" => { let on = v.as_bool().unwrap_or(false); save(|c| c.show_tray = on); - tray = if on { make_tray() } else { None }; + tray = if on { make_tray(&newer) } else { None }; } "login" => set_login(v.as_bool().unwrap_or(true), &proxy), // The page is drawn: size the panel to it, attach it and show it (no flash). @@ -263,6 +307,17 @@ pub fn run(background: bool) { } } "buy" => open_url(crate::license::BUY_URL), + "report" => open_url(&update::report_url()), + "update" => open_url(update::RELEASES_URL), + // Something on the page changed its height (such as the update notice). + "resize" => { + height = v.as_f64().unwrap_or(height); + if let Some((w, _)) = &win + && shown + { + place(w, anchor, height); + } + } "close" => { close_panel(&mut win, &mut shown, tray.is_some()); closed_at = std::time::Instant::now(); @@ -295,7 +350,7 @@ pub fn run(background: bool) { _ => {} } if let Some((_, wv)) = &win { - let _ = wv.evaluate_script(&format!("render({})", state(&status::read(), login, &names))); + let _ = wv.evaluate_script(&format!("render({})", state(&status::read(), login, &names, &newer))); } } // Dropping the window frees the web view entirely. @@ -310,14 +365,14 @@ pub fn run(background: bool) { // Opening MagicInput brings a hidden icon back, until it's hidden again from its menu. if opened && tray.is_none() { save(|c| c.show_tray = true); - tray = make_tray(); + tray = make_tray(&newer); } if show { match &win { // Kept from last time (icon mode): attach it again and replay the entrance. Some((w, wv)) if loaded && !w.is_visible() => { place(w, anchor, height); - let _ = wv.evaluate_script(&format!("reopen({})", state(&status::read(), login, &names))); + let _ = wv.evaluate_script(&format!("reopen({})", state(&status::read(), login, &names, &newer))); w.set_visible(true); w.set_focus(); shown = true; @@ -424,13 +479,14 @@ fn place(w: &Window, anchor: Option, height: f64) { w.set_outer_position(LogicalPosition::new(x, y)); } -fn make_tray() -> Option { +fn make_tray(newer: &Option) -> Option { let status = MenuItem::new("MagicInput", false, None); let menu = Menu::new(); menu.append_items(&[ &status, &PredefinedMenuItem::separator(), &MenuItem::with_id("settings", "Open MagicInput", true, None), + &MenuItem::with_id("report", "Report a Problem…", true, None), &MenuItem::with_id("hide", if cfg!(target_os = "macos") { "Hide from Menu Bar" } else { "Hide Icon" }, true, None), ]) .ok()?; @@ -441,14 +497,32 @@ fn make_tray() -> Option { let builder = TrayIconBuilder::new().with_icon(load_icon()?); let icon = builder .with_tooltip("MagicInput") - .with_menu(Box::new(menu)) + .with_menu(Box::new(menu.clone())) .with_menu_on_left_click(false) .build() .ok()?; #[cfg(target_os = "macos")] apply_vector_icon(&icon); status.set_text(status_line(&status::read())); - Some(Tray { _icon: icon, status }) + let mut tray = Tray { _icon: icon, menu, status, update: None }; + if let Some(v) = newer { + show_update(&mut tray, v); + } + Some(tray) +} + +/// Add "Update to x.y.z…" to the icon's menu, under the status line. +fn show_update(tray: &mut Tray, version: &str) { + let text = format!("Update to {version}…"); + match &tray.update { + Some(item) => item.set_text(text), + None => { + let item = MenuItem::with_id("update", text, true, None); + if tray.menu.insert(&item, 1).is_ok() { + tray.update = Some(item); + } + } + } } fn load_icon() -> Option { @@ -680,7 +754,7 @@ fn move_display(id: u32, x: f64, y: f64) { } } -fn state(st: &Option, login: bool, names: &[(Rect, String)]) -> String { +fn state(st: &Option, login: bool, names: &[(Rect, String)], newer: &Option) -> String { let c = Config::load(); let own = own_displays(st, names); let mine: Vec = own.iter().map(|d| d.0).collect(); @@ -724,6 +798,7 @@ fn state(st: &Option, login: bool, names: &[(Rect, String)]) -> "screens": screens, "peer_size": { "w": peer.w, "h": peer.h }, "placement": placement, + "update": newer, }) .to_string() } diff --git a/src/update.rs b/src/update.rs new file mode 100644 index 0000000..488ad3b --- /dev/null +++ b/src/update.rs @@ -0,0 +1,120 @@ +//! Telling people about a new version, and where to report a problem. Both are used by the +//! settings panel only; the background service never contacts a server for this. + +use std::process::Command; + +/// Where a new version is downloaded. The panel always opens this page, never a URL it was sent. +pub const RELEASES_URL: &str = "https://github.com/betoxf/Magicinput/releases/latest"; +const ISSUE_URL: &str = "https://github.com/betoxf/Magicinput/issues/new"; + +/// "1.2.3" (or "v1.2.3") as numbers; anything else, such as a pre-release, is `None`. +fn parse(version: &str) -> Option<(u32, u32, u32)> { + let mut parts = version.trim().trim_start_matches('v').split('.'); + let v = (parts.next()?.parse().ok()?, parts.next()?.parse().ok()?, parts.next()?.parse().ok()?); + parts.next().is_none().then_some(v) +} + +/// The version GitHub's latest-release page redirects to, from its response headers. +fn latest_in(headers: &str) -> Option<(u32, u32, u32)> { + let location = headers.lines().find_map(|l| { + let (name, value) = l.split_once(':')?; + name.trim().eq_ignore_ascii_case("location").then(|| value.trim()) + })?; + parse(location.rsplit_once("/releases/tag/")?.1) +} + +/// The newer version, formatted from the parsed numbers, if `latest` is ahead of `current`. +fn newer(current: &str, latest: (u32, u32, u32)) -> Option { + (latest > parse(current)?).then(|| format!("{}.{}.{}", latest.0, latest.1, latest.2)) +} + +/// Ask GitHub which version is the latest release: `Some(newer)` or `Some(None)` once known, +/// `None` if it couldn't be found out (offline, say). The request carries nothing about this +/// computer or its settings. +pub fn check() -> Option> { + let mut cmd = Command::new("curl"); + cmd.args(["-fsSI", "--max-time", "20", RELEASES_URL]); + #[cfg(windows)] + { + use std::os::windows::process::CommandExt; + cmd.creation_flags(0x0800_0000); // CREATE_NO_WINDOW + } + let out = cmd.output().ok()?; + Some(newer(env!("CARGO_PKG_VERSION"), latest_in(&String::from_utf8_lossy(&out.stdout))?)) +} + +/// A new bug report on GitHub, with this computer's MagicInput and system versions filled in. +/// Nothing else (no names, pairing code or logs) goes into the link. +pub fn report_url() -> String { + format!( + "{ISSUE_URL}?template=bug_report.yml&version={}&systems={}", + encode(env!("CARGO_PKG_VERSION")), + encode(&system()) + ) +} + +#[cfg(target_os = "macos")] +fn system() -> String { + let v = Command::new("sw_vers").arg("-productVersion").output().ok(); + let v = v.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()).unwrap_or_default(); + format!("macOS {v}").trim().to_string() +} + +#[cfg(windows)] +fn system() -> String { + use std::os::windows::process::CommandExt; + // "Microsoft Windows [Version 10.0.22631.4317]" + let out = Command::new("cmd").args(["/c", "ver"]).creation_flags(0x0800_0000).output().ok(); + let text = out.map(|o| String::from_utf8_lossy(&o.stdout).into_owned()).unwrap_or_default(); + let build: String = text.chars().filter(|c| c.is_ascii_digit() || *c == '.').collect(); + let build = build.trim_matches('.'); + // Windows 11 still reports 10.0; builds from 22000 on are Windows 11. + let name = match build.split('.').nth(2).and_then(|b| b.parse::().ok()) { + Some(b) if b >= 22000 => "Windows 11", + Some(_) => "Windows 10", + None => "Windows", + }; + if build.is_empty() { name.into() } else { format!("{name} ({build})") } +} + +/// Percent-encode a query value. +fn encode(s: &str) -> String { + s.bytes() + .map(|b| match b { + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => (b as char).to_string(), + _ => format!("%{b:02X}"), + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn reads_the_latest_version_from_the_redirect() { + let headers = "HTTP/2 302 \r\ndate: Mon, 16 Nov 2026 10:00:00 GMT\r\nLocation: https://github.com/betoxf/Magicinput/releases/tag/v0.7.0\r\n\r\n"; + assert_eq!(latest_in(headers), Some((0, 7, 0))); + assert_eq!(latest_in("HTTP/2 404 \r\n\r\n"), None); + assert_eq!(latest_in("location: https://github.com/betoxf/Magicinput/releases\r\n"), None); + assert_eq!(latest_in("location: https://github.com/betoxf/Magicinput/releases/tag/v1.0.0-beta\r\n"), None); + assert_eq!(latest_in("location: https://github.com/x/releases/tag/