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
10 changes: 10 additions & 0 deletions app/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ const ES = {
appTheme: "Tema",
appLanguage: "Idioma",
appPicker: "Selector",
pickerLook: "Estilo",
pickerClassic: "Clásico",
pickerSheet: "Mosaico",
pickerCompact: "Compacto",
pickerBear: "LinkBear",
pickerPreview: "Vista previa",
appPickerPosition: "Dónde aparece",
appPickerPositionNote: "En la pantalla donde está el puntero",
pickerByPointer: "Junto al puntero",
pickerCentered: "Al centro",
themeAuto: "Automático",
themeLight: "Claro",
themeDark: "Oscuro",
Expand Down Expand Up @@ -514,11 +519,16 @@ const EN: Record<Key, string> = {
appTheme: "Theme",
appLanguage: "Language",
appPicker: "Picker",
pickerLook: "Look",
pickerClassic: "Classic",
pickerSheet: "Tiles",
pickerCompact: "Compact",
pickerBear: "LinkBear",
pickerPreview: "Preview",
appPickerPosition: "Where it opens",
appPickerPositionNote: "On the screen the pointer is on",
pickerByPointer: "By the pointer",
pickerCentered: "Centered",
themeAuto: "Automatic",
themeLight: "Light",
themeDark: "Dark",
Expand Down
17 changes: 14 additions & 3 deletions app/src/settings/Application.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PREFS = {
shortcut: "Alt+Shift+L" as string | null,
notify_on_rule: true,
picker_style: "classic" as "bear" | "classic" | "sheet" | "compact",
picker_position: "pointer" as "pointer" | "center",
looks_for_updates: true,
};

Expand Down Expand Up @@ -69,7 +70,7 @@ describe("application settings", () => {

it("offers the tiles, and keeps the classic picker marked until they are chosen", async () => {
mount();
const picker = within(await screen.findByRole("group", { name: "Selector" }));
const picker = within(await screen.findByRole("group", { name: "Estilo" }));
expect(picker.getByRole("radio", { name: "Clásico" })).toBeChecked();
await userEvent.click(picker.getByRole("radio", { name: "Mosaico" }));
expect(invoke).toHaveBeenCalledWith("prefs_set", {
Expand All @@ -78,9 +79,19 @@ describe("application settings", () => {
});

/// Every look is offered, the bear among them, and each can be seen before it is kept.
it("opens the picker by the pointer until the center is chosen", async () => {
mount();
const where = within(await screen.findByRole("group", { name: "Dónde aparece" }));
expect(where.getByRole("radio", { name: "Junto al puntero" })).toBeChecked();
await userEvent.click(where.getByRole("radio", { name: "Al centro" }));
expect(invoke).toHaveBeenCalledWith("prefs_set", {
prefs: { ...PREFS, picker_position: "center" },
});
});

it("offers the four looks and shows the picker over a sample link", async () => {
mount();
const picker = within(await screen.findByRole("group", { name: "Selector" }));
const picker = within(await screen.findByRole("group", { name: "Estilo" }));
for (const look of ["LinkBear", "Clásico", "Mosaico", "Compacto"]) {
expect(picker.getByRole("radio", { name: look })).toBeInTheDocument();
}
Expand All @@ -91,7 +102,7 @@ describe("application settings", () => {
/// Once a preview is up, choosing another look redraws it rather than leaving the old one open.
it("redraws the preview when another look is chosen", async () => {
mount();
const picker = within(await screen.findByRole("group", { name: "Selector" }));
const picker = within(await screen.findByRole("group", { name: "Estilo" }));
await userEvent.click(picker.getByRole("radio", { name: "Mosaico" }));
expect(invoke.mock.calls.filter(([cmd]) => cmd === "picker_preview")).toHaveLength(0);

Expand Down
26 changes: 24 additions & 2 deletions app/src/settings/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Card, Line, Section, Switch } from "./parts";
type Theme = "system" | "light" | "dark";
type Locale = "system" | "spanish" | "english";
type PickerStyle = "bear" | "classic" | "sheet" | "compact";
type PickerPosition = "pointer" | "center";

type Preferences = {
schema_version: number;
Expand All @@ -16,6 +17,7 @@ type Preferences = {
shortcut: string | null;
notify_on_rule: boolean;
picker_style: PickerStyle;
picker_position: PickerPosition;
looks_for_updates: boolean;
};

Expand All @@ -40,6 +42,11 @@ const PICKERS: { id: PickerStyle; label: Key }[] = [
{ id: "compact", label: "pickerCompact" },
];

const POSITIONS: { id: PickerPosition; label: Key }[] = [
{ id: "pointer", label: "pickerByPointer" },
{ id: "center", label: "pickerCentered" },
];

const MODIFIERS = new Set(["Control", "Alt", "Shift", "Meta"]);

const RESIDENT_ANSWERS_WITHIN = 1400;
Expand Down Expand Up @@ -179,12 +186,17 @@ export default function Application({
onPick={(locale) => apply({ locale })}
/>
</Line>
<Line title={t("appPicker")}>
</Card>
</Section>

<Section title={t("appPicker")}>
<Card>
<Line title={t("pickerLook")}>
<div className="flex shrink-0 flex-col items-end gap-1.5">
<Choice
options={PICKERS}
value={prefs.picker_style}
label={t("appPicker")}
label={t("pickerLook")}
onPick={(picker_style) => apply({ picker_style }, previewing ? preview : undefined)}
/>
<button
Expand All @@ -196,6 +208,16 @@ export default function Application({
</button>
</div>
</Line>
<Line title={t("appPickerPosition")} note={t("appPickerPositionNote")}>
<Choice
options={POSITIONS}
value={prefs.picker_position}
label={t("appPickerPosition")}
onPick={(picker_position) =>
apply({ picker_position }, previewing ? preview : undefined)
}
/>
</Line>
</Card>
</Section>

Expand Down
1 change: 1 addition & 0 deletions crates/linkunbound-core/src/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ catalogue! {
picker_remember: "Recordar esta elección" | "Remember this choice",
picker_private: "Privada" | "Private",
picker_copy: "Copiar la dirección" | "Copy the address",
picker_close: "Cerrar" | "Close",
picker_ask: "¿Dónde abro este enlace?" | "Where should this link open?",
picker_ask_private: "¿Dónde lo abro en privado?" | "Where should it open privately?",
picker_private_line: "Se abrirá en una ventana privada" | "It will open in a private window",
Expand Down
2 changes: 1 addition & 1 deletion crates/linkunbound-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use icons::{cached_icon, prune as prune_icons};
pub use journal::{JOURNAL, journal, note, scrubbed};
pub use launch::{LaunchError, open as launch, spawn_and_forget};
pub use news::{behind as news_behind, untold as untold_news};
pub use prefs::{Locale, PickerStyle, Preferences, Theme};
pub use prefs::{Locale, PickerPosition, PickerStyle, Preferences, Theme};
pub use private::private_flag_for;
pub use report::{diagnostics, redact};
pub use rule::{
Expand Down
28 changes: 27 additions & 1 deletion crates/linkunbound-core/src/prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub enum PickerStyle {
Bear,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PickerPosition {
#[default]
Pointer,
Center,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Preferences {
#[serde(default)]
Expand All @@ -49,6 +57,8 @@ pub struct Preferences {
pub edge_warning_dismissed: bool,
#[serde(default)]
pub picker_style: PickerStyle,
#[serde(default)]
pub picker_position: PickerPosition,
/// Whether the resident asks about releases on its own, every few hours; off, only the
/// settings window ever asks, and only while it is open.
#[serde(default = "yes")]
Expand Down Expand Up @@ -82,6 +92,7 @@ impl Default for Preferences {
notify_on_rule: true,
edge_warning_dismissed: false,
picker_style: PickerStyle::default(),
picker_position: PickerPosition::default(),
looks_for_updates: true,
here_since: None,
asked_for_a_star: false,
Expand Down Expand Up @@ -163,7 +174,7 @@ fn shortcut_of(said: &str) -> Option<String> {

#[cfg(test)]
mod tests {
use super::{Locale, PickerStyle, Preferences, Theme};
use super::{Locale, PickerPosition, PickerStyle, Preferences, Theme};

#[test]
fn a_fresh_install_follows_the_system_and_claims_the_default_shortcut() {
Expand Down Expand Up @@ -282,6 +293,21 @@ mod tests {
assert!(written.contains(r#""picker_style":"sheet""#), "{written}");
}

#[test]
fn the_picker_opens_by_the_pointer_unless_the_center_was_asked_for() {
let fresh: Preferences = serde_json::from_str("{}").unwrap();
assert_eq!(fresh.picker_position, PickerPosition::Pointer);

let asked: Preferences = serde_json::from_str(r#"{"picker_position": "center"}"#).unwrap();
assert_eq!(asked.picker_position, PickerPosition::Center);

let written = serde_json::to_string(&asked).unwrap();
assert!(
written.contains(r#""picker_position":"center""#),
"{written}"
);
}

/// Everybody moves to the bear once; after that, what they pick stays picked.
#[test]
fn the_bear_comes_once_and_a_later_choice_stands() {
Expand Down
8 changes: 7 additions & 1 deletion crates/linkunbound-shell/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
fn main() {
slint_build::compile("ui/shell.slint").expect("the interface must compile");
// Tests find the picker's buttons by id; a release build carries no ids it would never use.
let debug = std::env::var("PROFILE").as_deref() == Ok("debug");
slint_build::compile_with_config(
"ui/shell.slint",
slint_build::CompilerConfiguration::new().with_debug_info(debug),
)
.expect("the interface must compile");

#[cfg(windows)]
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
Expand Down
1 change: 1 addition & 0 deletions crates/linkunbound-shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ pub fn dress(window: &Picker, words: &Strings, url: &str, source: Option<&str>,
window.set_chosen_at(-1);
window.set_preview(false);
window.set_copy_label(words.picker_copy.into());
window.set_close_label(words.picker_close.into());
window.set_update_later(words.update_later.into());
window.set_private_on(false);
// Pinned for a link, not for the day: left set, every later picker opened privately.
Expand Down
Loading
Loading