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
8 changes: 5 additions & 3 deletions src/gpui_shell/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ use super::{ExitFlags, ascii};
use crate::overlay::Overlay;
use crate::runtime::{
BridgeCommand, UpdateEvent, WINDOW_HEIGHT, WINDOW_WIDTH, notify_natively, open_logs,
open_openmouse, service_label,
service_label,
};

const OPENMOUSE_URL: &str = "https://control.openmouse.app";

/// The low-battery alert levels on offer.
const BATTERY_THRESHOLDS: [u8; 7] = [10, 15, 20, 25, 30, 40, 50];
const VOLUME_STEP: u8 = 10;
Expand Down Expand Up @@ -908,8 +910,8 @@ impl PanelView {
.primary()
.compact()
.label("Open OpenMouse")
.on_click(cx.listener(|_, _, _, _| {
let _ = open_openmouse();
.on_click(cx.listener(|_, _, _, cx| {
cx.open_url(OPENMOUSE_URL);
})),
)
.child(
Expand Down
59 changes: 0 additions & 59 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ use openmouse_bridge::{
};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use std::io::Cursor;
#[cfg(target_os = "windows")]
use std::ptr::null_mut;
use tokio::{
net::TcpListener,
sync::{mpsc as tokio_mpsc, oneshot},
};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use tray_icon::Icon;
#[cfg(target_os = "windows")]
use windows_sys::Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_SHOWNORMAL};

const OPENMOUSE_URL: &str = "https://control.openmouse.app";

/// Present when the user explicitly wants no tray panel (or when no display
/// exists): Bridge serves its HTTP API, HID, and game profiles without a
Expand Down Expand Up @@ -614,59 +608,6 @@ pub(crate) fn open_logs() -> Result<()> {
Ok(())
}

pub(crate) fn open_openmouse() -> Result<()> {
open_url(OPENMOUSE_URL)
}

#[cfg(target_os = "windows")]
fn open_url(url: &str) -> Result<()> {
let operation = wide("open");
let target = wide(url);
let result = unsafe {
ShellExecuteW(
null_mut(),
operation.as_ptr(),
target.as_ptr(),
null_mut(),
null_mut(),
SW_SHOWNORMAL,
)
} as isize;
if result <= 32 {
return Err(anyhow!("Windows could not open {url} (code {result})"));
}
Ok(())
}

#[cfg(target_os = "macos")]
fn open_url(url: &str) -> Result<()> {
let status = std::process::Command::new("open")
.arg(url)
.status()
.with_context(|| format!("macOS could not open {url}"))?;
if !status.success() {
return Err(anyhow!("macOS could not open {url}"));
}
Ok(())
}

#[cfg(target_os = "linux")]
fn open_url(url: &str) -> Result<()> {
let status = std::process::Command::new("xdg-open")
.arg(url)
.status()
.with_context(|| format!("Linux could not open {url}"))?;
if !status.success() {
return Err(anyhow!("Linux could not open {url}"));
}
Ok(())
}

#[cfg(target_os = "windows")]
fn wide(value: &str) -> Vec<u16> {
value.encode_utf16().chain(Some(0)).collect()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading