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: 2 additions & 2 deletions .github/oversized.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2030 app/src-tauri/src/lib.rs
2032 crates/linkunbound-shell/src/main.rs
2026 app/src-tauri/src/lib.rs
1969 crates/linkunbound-shell/src/main.rs
16 changes: 6 additions & 10 deletions app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,6 @@ fn prefs_set(app: AppHandle, prefs: Preferences) -> Result<Settings, String> {
Ok(claim(&settled))
}

#[tauri::command]
fn system_open_default_apps() -> Result<(), String> {
system::open_default_apps()
}

/// Re-registers against this executable, which is the only repair there is: the
/// command pointed somewhere this binary no longer lives.
#[tauri::command(async)]
Expand Down Expand Up @@ -1058,7 +1053,7 @@ fn relay_links(app: AppHandle) {
hand_to_the_resident(url);
}
}
Event::Reopened => shell::open_settings(&app, store().prefs().theme),
Event::Reopened => shell::open_settings(&app, store().prefs().theme, None),
Event::Launched { .. } => {}
});
std::mem::forget(listening);
Expand Down Expand Up @@ -1240,13 +1235,14 @@ pub fn run() {
about::maintenance_report,
prefs_get,
prefs_set,
shell::picker_preview,
system_state,
system_legacy,
system_retire_legacy,
system_reveal_legacy,
system_set_registered,
system_set_startup,
system_open_default_apps,
system::system_open_default_apps,
system_repair,
system_register_anyway,
system_open_elsewhere,
Expand All @@ -1267,8 +1263,8 @@ pub fn run() {
let builder = if errand.is_some() {
builder
} else {
builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
shell::open_settings(app, store().prefs().theme);
builder.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
shell::open_settings(app, store().prefs().theme, shell::page_in(&args));
}))
};

Expand Down Expand Up @@ -1298,7 +1294,7 @@ pub fn run() {
news::raise(app.handle());
#[cfg(target_os = "macos")]
relay_links(app.handle().clone());
shell::open_settings(app.handle(), store().prefs().theme);
shell::open_settings(app.handle(), store().prefs().theme, shell::page_in(&args));
Ok(())
})
.build(tauri::generate_context!())
Expand Down
50 changes: 45 additions & 5 deletions app/src-tauri/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,57 @@

/// Built on demand: an idle webview costs tens of megabytes and this window is
/// opened rarely. The resident owns the tray, the picker and the notice.
pub fn open_settings<R: Runtime>(app: &AppHandle<R>, theme: Theme) {
/// The page the command line asks settings to open on, when it asks for one.
#[must_use]
pub fn page_in(args: &[String]) -> Option<&'static str> {
args.iter()
.any(|a| a == linkunbound_core::BROWSERS)
.then_some("browsers")
}

pub fn open_settings<R: Runtime>(app: &AppHandle<R>, theme: Theme, page: Option<&str>) {
if let Some(window) = app.get_webview_window(SETTINGS) {
if let Some(page) = page {
let _ = window.eval(format!("location.hash = '{page}'"));
}
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();
return;
}
if BUILDING.swap(true, Ordering::AcqRel) {
return;
}
let _building = Building;
build_settings(app, theme);
build_settings(app, theme, page);

Check warning on line 103 in app/src-tauri/src/shell.rs

View workflow job for this annotation

GitHub Actions / settings / the lines this branch changed

Missed mutant

replace open_settings with ()
}

const LONG_ENOUGH_TO_PAINT: std::time::Duration = std::time::Duration::from_millis(1500);

fn build_settings<R: Runtime>(app: &AppHandle<R>, theme: Theme) {
let mut builder = tauri::WebviewWindowBuilder::new(app, SETTINGS, tauri::WebviewUrl::default())
fn build_settings<R: Runtime>(app: &AppHandle<R>, theme: Theme, page: Option<&str>) {
let url = page.map_or_else(tauri::WebviewUrl::default, |page| {
tauri::WebviewUrl::App(format!("index.html#{page}").into())
});
let mut builder = tauri::WebviewWindowBuilder::new(app, SETTINGS, url)
.title("LinkUnbound")
.inner_size(780.0, 560.0)
.min_inner_size(640.0, 480.0)
.resizable(true)
.visible(false)
.theme(dressed_as(theme));
if let Some(color) = ground(theme) {
builder = builder.background_color(color);
}
let built = builder.build();
if let Ok(window) = built {
dress_natively(&window, theme);
drop_the_title_icon(&window);
let late = window.clone();
std::thread::spawn(move || {
std::thread::sleep(LONG_ENOUGH_TO_PAINT);
reveal(&late);
});
}

Check warning on line 131 in app/src-tauri/src/shell.rs

View workflow job for this annotation

GitHub Actions / settings / the lines this branch changed

Missed mutant

replace build_settings with ()
}

pub fn reveal<R: Runtime>(window: &tauri::WebviewWindow<R>) {
Expand All @@ -127,7 +141,17 @@

#[cfg(test)]
mod tests {
use super::{SETTINGS, dressed_as};
use super::{SETTINGS, dressed_as, page_in};

#[test]
fn the_picker_can_send_settings_to_the_browsers() {
let said = |args: &[&str]| args.iter().map(|&a| a.to_owned()).collect::<Vec<_>>();
assert_eq!(
page_in(&said(&["settings.exe", "--browsers"])),
Some("browsers")
);
assert_eq!(page_in(&said(&["settings.exe"])), None);
}
use linkunbound_core::Theme;

#[test]
Expand Down Expand Up @@ -161,3 +185,19 @@
assert!(!config.contains("\"label\":"));
}
}

/// The picker over a sample link, so a look can be seen before it is kept. A resident already
/// running takes the word over its socket; with none, one is started with it.
#[tauri::command]
pub fn picker_preview() {
if linkunbound_shell::single::hand_over(linkunbound_core::PREVIEW) {
return;
}
let Ok(here) = std::env::current_exe() else {
return;
};
let _ = linkunbound_core::spawn_and_forget(
std::process::Command::new(linkunbound_core::link_handler(&here))
.arg(linkunbound_core::PREVIEW),
);

Check warning on line 202 in app/src-tauri/src/shell.rs

View workflow job for this annotation

GitHub Actions / settings / the lines this branch changed

Missed mutant

replace picker_preview with ()
}
5 changes: 5 additions & 0 deletions app/src-tauri/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,8 @@
browsers, legacy, open_default_apps, reconcile, register_anyway, register_for_the_installer,
retire_legacy, reveal_legacy, set_registered, set_starts_with_system, state,
};

#[tauri::command]
pub fn system_open_default_apps() -> Result<(), String> {
open_default_apps()

Check warning on line 621 in app/src-tauri/src/system.rs

View workflow job for this annotation

GitHub Actions / settings / the lines this branch changed

Missed mutant

replace system_open_default_apps -> Result<(), String> with Ok(())
}
Loading
Loading