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
17 changes: 12 additions & 5 deletions frontend/src/components/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ open, onOpenChange }) =>
};

// Download update
const handleViewReleaseNotes = async () => {
if (!updateInfo?.release_url) return;
try {
await invoke('open_url', { url: updateInfo.release_url });
} catch (error) {
console.error('Failed to open release notes:', error);
}
};

const handleDownloadUpdate = async () => {
if (!updateInfo?.download_url || !updateInfo?.asset_name) return;

Expand Down Expand Up @@ -726,11 +735,9 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ open, onOpenChange }) =>
<Button className="flex-1" size="sm" onClick={handleDownloadUpdate}>
{t('settings.downloadAndInstall')}
</Button>
<Button variant="secondary" size="sm" asChild>
<a href={updateInfo.release_url} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1">
<ExternalLink size={12} />
<span>{t('settings.viewReleaseNotes')}</span>
</a>
<Button variant="secondary" size="sm" onClick={handleViewReleaseNotes} className="flex items-center gap-1">
<ExternalLink size={12} />
<span>{t('settings.viewReleaseNotes')}</span>
</Button>
<Button variant="secondary" size="sm" onClick={handleCancelUpdate}>
{t('settings.cancel')}
Expand Down
8 changes: 7 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ async fn launch_installer_and_exit(installer_path: String) -> Result<(), String>
updater::launch_installer_and_exit(&installer_path)
}

#[tauri::command]
fn open_url(url: String) -> Result<(), String> {
updater::open_url(&url)
}

fn main() {
env_logger::init();

Expand Down Expand Up @@ -480,7 +485,8 @@ fn main() {
get_display_settings,
check_for_updates,
download_update,
launch_installer_and_exit
launch_installer_and_exit,
open_url
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
34 changes: 34 additions & 0 deletions src-tauri/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,33 @@ pub fn launch_installer_and_exit(installer_path: &str) -> Result<(), String> {
std::process::exit(0);
}

/// Open a URL in the system browser (release notes, project page, …).
///
/// Plain `<a target="_blank">` is a no-op inside the Tauri webview, so the
/// frontend hands external links here instead of using the shell plugin.
pub fn open_url(url: &str) -> Result<(), String> {
// Cheap sanity check: only web URLs may be handed to the OS opener.
if !(url.starts_with("https://") || url.starts_with("http://")) {
return Err(format!("Refusing to open non-http(s) URL: {}", url));
}

let status = if cfg!(target_os = "macos") {
Command::new("open").arg(url).status()
} else if cfg!(target_os = "windows") {
Command::new("rundll32")
.args(["url.dll,FileProtocolHandler", url])
.status()
} else {
Command::new("xdg-open").arg(url).status()
};

match status {
Ok(s) if s.success() => Ok(()),
Ok(s) => Err(format!("System URL opener exited with {}", s)),
Err(e) => Err(format!("Failed to launch URL opener: {}", e)),
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -317,6 +344,13 @@ mod tests {
assert_eq!(compare_versions("2.0.0", "1.9.9"), Some(Ordering::Greater));
}

#[test]
fn open_url_rejects_non_http_schemes() {
assert!(open_url("file:///etc/passwd").is_err());
assert!(open_url("javascript:alert(1)").is_err());
assert!(open_url("").is_err());
}

fn asset(name: &str) -> GitHubAsset {
GitHubAsset {
name: name.to_string(),
Expand Down
Loading