diff --git a/modules/shell/scripts/e2e_window.py b/modules/shell/scripts/e2e_window.py index f9fe759b..98a4fb34 100644 --- a/modules/shell/scripts/e2e_window.py +++ b/modules/shell/scripts/e2e_window.py @@ -2041,10 +2041,12 @@ def last_screen(browser) -> str: browser.execute_script(f"location.hash = '#/meeting/{first.name}'") wait_for(browser, lambda b: b.find_elements(By.ID, "make-minutes"), 10) press(browser, "make-minutes") - told = wait_for(browser, lambda b: "Aucun modèle choisi pour les comptes rendus" in notified.read_text(), 10) - opened = wait_for(browser, lambda b: b.find_element(By.ID, "settings").is_displayed(), 5) - check("connected, no service chosen after: the first meeting's minutes say none is, and open Settings", - told and opened and not (first / "minutes.md").exists() and "minutes_provider" not in window.file.read_text(), + # Asked from its page in front: Settings opened say it, never a notification (D25, D92). + opened = wait_for(browser, lambda b: b.find_element(By.ID, "settings").is_displayed(), 10) + time.sleep(1) + told = "Aucun modèle choisi pour les comptes rendus" in notified.read_text() + check("connected, no service chosen after: the first meeting's minutes open Settings, nothing notified from its page in front (D92)", + not told and opened and not (first / "minutes.md").exists() and "minutes_provider" not in window.file.read_text(), (notified.read_text()[-300:], window.file.read_text())) finally: monitor.terminate() @@ -2164,6 +2166,18 @@ def part(read): (heard / "language").unlink() +# Another application, as the user's: a window of its own the desktop gives the focus to, as it +# gives it any window shown (headless.sh's extension) — Kitokey's own window still seen beside it. +ELSEWHERE = """ +import gi +gi.require_version("Gtk", "4.0") +from gi.repository import Gio, Gtk +app = Gtk.Application(application_id="org.example.Elsewhere", flags=Gio.ApplicationFlags.NON_UNIQUE) +app.connect("activate", lambda a: Gtk.ApplicationWindow(application=a, title="Elsewhere").present()) +app.run([]) +""" + + def app_language(now: dt.datetime) -> None: """AF. The language Kitokey speaks, chosen in Settings, the system's by default (D64).""" print("AF. the app's language chosen in Settings: spoken at once and after a restart, never the meetings' (D64)") @@ -2189,12 +2203,23 @@ def app_language(now: dt.datetime) -> None: sections = lambda b: b.execute_script("return [document.getElementById('settings-link').getAttribute('aria-label'), document.documentElement.lang]") redo = lambda b: b.execute_script("window.__TAURI__.core.invoke('transcript_redo', {name: arguments[0], model: arguments[1]})", heard.name, str(model)) + def away(b, made) -> None: + """A making's end awaited with another application in front: told only then (D92).""" + other = subprocess.Popen(["/usr/bin/python3", "-c", ELSEWHERE], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + try: + wait_for(b, lambda b: not b.execute_script("return document.hasFocus()"), 10) + made() + finally: + other.terminate() + other.wait(timeout=10) + wait_for(b, lambda b: b.execute_script("return document.hasFocus()"), 5) + def by_settings(b, ready: str) -> str: """The transcript made again by whoever the settings name to hear (D59): what it was told.""" args.unlink(missing_ok=True) count = notified.read_text().count(ready) - b.execute_script("window.__TAURI__.core.invoke('context_redo', {name: arguments[0]})", heard.name) - wait_for(b, lambda b: told() != "" and notified.read_text().count(ready) > count, 15) + away(b, lambda: (b.execute_script("window.__TAURI__.core.invoke('context_redo', {name: arguments[0]})", heard.name), + wait_for(b, lambda b: told() != "" and notified.read_text().count(ready) > count, 15))) return told() notified = WORK / "notified-language" @@ -2241,8 +2266,7 @@ def by_settings(b, ready: str) -> str: stops[-2][0] == "general-advanced" and opened == "true" and stops[-1][0] == "developer" and all(seen_ for _, seen_ in stops), (opened, [s_ for s_ in stops if not s_[1]] or stops[-3:])) press(browser, "general-advanced") - redo(browser) - wait_for(browser, lambda b: "Transcription prête" in notified.read_text(), 15) + away(browser, lambda: (redo(browser), wait_for(browser, lambda b: "Transcription prête" in notified.read_text(), 15))) before = by_settings(browser, "Transcription prête") spoke = len(asked.read_text()) choose(browser, "app-language", "en") @@ -5575,8 +5599,8 @@ def actions_rows(now: dt.datetime) -> None: def meeting_told_once(now: dt.datetime) -> None: - """AL. A meeting's notifications are fewer, and a click on one opens the meeting (D44).""" - print("AL. a window seen: no stop told, the transcript not told before its minutes; their notification's click opens the meeting (D44)") + """BN. A meeting made after a stop is told once, naming it, and only where no window of Kitokey has the focus (D44, D92).""" + print("BN. the last step's end: none told while a window of Kitokey has the focus; else one notification, naming the meeting, its click opening it (D92)") meetings = WORK / "telling" meetings.mkdir() model = WORK / "telling-model.bin" @@ -5589,20 +5613,79 @@ def meeting_told_once(now: dt.datetime) -> None: for rule, out in (("interface='org.freedesktop.Notifications',member='Notify'", notified), ("type='method_return',sender='org.freedesktop.Notifications'", answered))] live = lambda b: "live" in (b.find_element(By.ID, "record").get_attribute("class") or "") + focused = lambda b: b.execute_script("return document.hasFocus()") + idle = lambda b: b.execute_script("return window.__TAURI__.core.invoke('makings').then(m => m.transcript === null" + " && m.transcripts_waiting.length === 0 && m.minutes === null && m.minutes_waiting.length === 0)") + told = lambda mark: notified.read_text()[mark:] + # What each Notify seen was, for a check that fails: its sender, whether the desktop relayed it + # (`x-shell-sender`), its title and body — a count alone does not say which. + seen = lambda mark: [(m.split(' ', 1)[0], 'x-shell-sender' in m, re.findall(r'^ string "(.*)"$', m, re.M)[2:4]) + for m in told(mark).split('sender=')[1:] if 'member=Notify' in m.split('\n', 1)[0]] + # Those Kitokey sent: the desktop may relay one (`x-shell-sender`), the same notification again. + sent = lambda mark: [notice for notice in seen(mark) if not notice[1]] + # The meeting as the notification names it: no title of its own, so its day and hour. + names = lambda text: "18 oct." in text and "12:00" in text + other = None + done = WORK / "telling-done" + done.mkdir() + + def stopped(browser, title: str | None = None) -> bool: + """A recording started and stopped from the window, as the record button does — by the page's + own click, which moves no focus —; the meeting before it set out of the list first, its folder + being the one the played recorder writes. `title`: the meeting named while it is recorded.""" + if meeting.exists(): + shutil.move(meeting, done / str(len(list(done.iterdir())))) + browser.execute_script("document.getElementById('record').click()") + started = wait_for(browser, lambda b: (meeting / "session.json").exists() and live(b), 10) + if title: + (meeting / "title.txt").write_text(title + "\n") + # The button says it at the click now (D68); a press within half a second is the same press. + time.sleep(0.6) + browser.execute_script("document.getElementById('record').click()") + return started + + def elsewhere(browser) -> bool: + """Another application's window in front, Kitokey's still seen.""" + nonlocal other + if other is not None: + other.terminate() + other.wait(timeout=10) + other = subprocess.Popen(["/usr/bin/python3", "-c", ELSEWHERE], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + return wait_for(browser, lambda b: not focused(b), 10) + + def one_told(browser, mark: int, until) -> bool: + """The making's end awaited, then two seconds more for a notification that would follow it.""" + ended = wait_for(browser, lambda b: until(told(mark)) and idle(b), 20) + time.sleep(2) + return ended and len(sent(mark)) == 1 + + unchosen = f'after = "minutes"\nreminder = false\nmodel = "{model}"\n' try: time.sleep(0.5) - with Window(meetings, "fr_FR.UTF-8", settings) as browser: + window = Window(meetings, "fr_FR.UTF-8", settings) + with window as browser: + # 1. The window has the focus: made after a stop, transcript then minutes, nothing told. + check("the window has the focus, as the desktop gives it", wait_for(browser, focused, 5)) browser.find_element(By.ID, "record").click() wait_for(browser, lambda b: (meeting / "session.json").exists() and live(b), 10) - # The button says it at the click now (D68); a press within half a second is the same press. time.sleep(0.6) browser.find_element(By.ID, "record").click() - made = wait_for(browser, lambda b: "Compte rendu prêt" in notified.read_text(), 20) - told = notified.read_text() - check("a window seen: the stop is not told, nor the transcript before its minutes — their notification alone", - made and "Enregistrement arrêté" not in told and "Transcription prête" not in told, told[-600:]) - check("its words say the click opens it", "Cliquez pour l’ouvrir." in told, told[-400:]) - # Away from the meeting, then the notification clicked as the desktop clicks it. + made = wait_for(browser, lambda b: (meeting / "minutes.md").exists() and idle(b), 20) + time.sleep(2) + check("a window of Kitokey has the focus: the stop, the transcript and its minutes made, nothing told", + made and focused(browser) and not sent(0), seen(0)) + + # 2. Another application has the focus: a stop, its transcript then its minutes — one + # notification, the minutes', naming the meeting. + check("another application has the focus, Kitokey's window still seen", + elsewhere(browser) and browser.find_element(By.ID, "meeting").is_displayed()) + mark = len(notified.read_text()) + recorded = stopped(browser) + ready = one_told(browser, mark, lambda t: "Compte rendu prêt" in t) + check("the focus elsewhere, a stop: one notification, the minutes', naming the meeting — the transcript not told on its own", + recorded and ready and not focused(browser) and "Transcription prête" not in told(mark) + and names(told(mark)) and "Cliquez pour l’ouvrir." in told(mark), seen(mark)) + # Clicked as the desktop clicks it: the full window opens on that meeting's page. browser.execute_script("location.hash = '#/settings'") wait_for(browser, lambda b: b.find_element(By.ID, "settings").is_displayed(), 5) number = re.findall(r"^ +uint32 (\d+)", answered.read_text(), re.M)[-1] @@ -5612,26 +5695,83 @@ def meeting_told_once(now: dt.datetime) -> None: and b.find_element(By.ID, "meeting").is_displayed(), 10) check("clicked: the full window opens on that meeting's page, never the file manager", opened, browser.execute_script("return location.hash")) - # Its transcript made again (Refaire…): ready, its click opens the meeting too. - (meeting / "local.wav").write_bytes(b"\0" * 1000) + + # The same meeting made again, its minutes after: their notification alone — the redo's + # own path, which tells nothing of the transcript when the minutes follow it. + elsewhere(browser) mark = len(notified.read_text()) - browser.execute_script("window.__TAURI__.core.invoke('transcript_redo', {name: arguments[0], model: arguments[1]})", - meeting.name, str(model)) - again = wait_for(browser, lambda b: "Transcription prête" in notified.read_text()[mark:], 15) - browser.execute_script("location.hash = '#/settings'") - wait_for(browser, lambda b: b.find_element(By.ID, "settings").is_displayed(), 5) - number = re.findall(r"^ +uint32 (\d+)", answered.read_text(), re.M)[-1] - subprocess.run(["gdbus", "emit", "--session", "--object-path", "/org/freedesktop/Notifications", "--signal", - "org.freedesktop.Notifications.ActionInvoked", f"uint32 {number}", "'default'"], capture_output=True) - reopened = wait_for(browser, lambda b: b.execute_script("return location.hash") == f"#/meeting/{meeting.name}", 10) - check("a transcript made again says the click opens it, and the click does", - again and "Cliquez pour l’ouvrir." in notified.read_text()[mark:] and reopened, browser.execute_script("return location.hash")) + browser.execute_script("window.__TAURI__.core.invoke('context_redo', {name: arguments[0]})", meeting.name) + again = one_told(browser, mark, lambda t: "Compte rendu prêt" in t) + check("made again, its minutes after: one notification, the minutes', naming the meeting", + again and "Transcription prête" not in told(mark) and names(told(mark)), seen(mark)) + + # 3. A meeting given a title, its minutes failed: one notification, the failure's, naming + # it by its title, not its hour. + elsewhere(browser) + (WORK / "fail-minutes").touch() + mark = len(notified.read_text()) + recorded = stopped(browser, "Point hebdo") + failed = one_told(browser, mark, lambda t: "member=Notify" in t) + check("titled, its minutes failed: one notification, the failure's, naming the meeting by its title — the transcript not told on its own", + recorded and failed and not focused(browser) and "Transcription prête" not in told(mark) + and "Compte rendu prêt" not in told(mark) and "Point hebdo" in told(mark) and not names(told(mark)), seen(mark)) + (WORK / "fail-minutes").unlink() + + # 4. No model where the settings name one: the transcript cannot start, the meeting's + # last step; then its program missing. Each told once, naming the meeting (D92). + window.file.write_text(settings.replace(str(model), str(WORK / "telling-absent.bin"))) + elsewhere(browser) + mark = len(notified.read_text()) + recorded = stopped(browser) + missing = one_told(browser, mark, lambda t: "member=Notify" in t) + check("no model: one notification, what to do, naming the meeting", + recorded and missing and not focused(browser) and "le modèle manque" in told(mark) + and "Placez le modèle Whisper" in told(mark) and names(told(mark)), seen(mark)) + window.file.write_text(settings) + elsewhere(browser) + HEARING.chmod(0o644) + mark = len(notified.read_text()) + recorded = stopped(browser) + unstarted = one_told(browser, mark, lambda t: "member=Notify" in t) + HEARING.chmod(0o755) + check("its transcription program cannot start: one notification, what to do, naming the meeting", + recorded and unstarted and not focused(browser) and "Kitokey ne peut pas transcrire" in told(mark) + and "réinstaller Kitokey" in told(mark) and names(told(mark)), seen(mark)) + + # 5. Its minutes not started — nobody named to write them: the transcript's end is the last + # step's, one notification still, D25's, saying what to do and naming the meeting (D25, D92). + window.file.write_text(unchosen) + elsewhere(browser) + mark = len(notified.read_text()) + recorded = stopped(browser) + asked = one_told(browser, mark, lambda t: "member=Notify" in t) + check("its minutes not started: one notification, what to do for them, naming the meeting — the transcript not told on its own", + recorded and asked and "Transcription prête" not in told(mark) and "Aucun modèle choisi" in told(mark) + and "Choisissez-le dans les réglages" in told(mark) and names(told(mark)), seen(mark)) + + # 6. The same with Kitokey's window focused: nothing told, the window says it — Settings, + # where the model is chosen. + other.terminate() + other.wait(timeout=10) + other = None + check("Kitokey's window has the focus again", wait_for(browser, focused, 10)) + browser.execute_script("location.hash = '#/'") + mark = len(notified.read_text()) + recorded = stopped(browser) + shown = wait_for(browser, lambda b: b.execute_script("return location.hash") == "#/settings" and idle(b), 20) + time.sleep(2) + check("its minutes not started, a window of Kitokey focused: nothing told, the window opened on Settings", + recorded and shown and focused(browser) and not sent(mark), seen(mark)) finally: + HEARING.chmod(0o755) + (WORK / "fail-minutes").unlink(missing_ok=True) + if other is not None: + other.terminate() + other.wait(timeout=10) for monitor in monitors: monitor.terminate() monitor.wait(timeout=10) - def two_panes(now: dt.datetime) -> None: """AD. The window in two panes: the meetings in a sidebar, the one chosen beside them (D61).""" print("AD. the window in two panes: the sidebar, the meeting chosen beside it, as wide as the window (D61)") @@ -9045,14 +9185,16 @@ def aside(folder): wait_for(browser, lambda b: b.find_elements(By.ID, "redo-do")) redo_pick(browser, "redo-panel", "minutes", 1) browser.find_element(By.ID, "redo-do").click() - told = wait_for(browser, lambda b: "pas été refait" in heard.read_text(), 10) - check("minutes made again that fail: the ones there stay, and the notice says a redo", told and (asked / "minutes.md").read_text() == before, heard.read_text()[-400:]) - failed = wait_for(browser, lambda b: "n’a pas été fait" in state(b) and b.find_elements(By.ID, "minutes-again"), 5) + # Made from its page, Kitokey's window in front: its end told there, never by a notification (D92). + failed = wait_for(browser, lambda b: "n’a pas été fait" in state(b) and b.find_elements(By.ID, "minutes-again"), 10) + time.sleep(1) + check("minutes made again that fail, from their page in front: the ones there stay, nothing notified (D92)", + failed and (asked / "minutes.md").read_text() == before and "member=Notify" not in heard.read_text(), heard.read_text()[-400:]) check("the failure said on the meeting's page too, in plain words, with a way to try again — never what the program said", failed and "not minutes" not in state(browser) and "not minutes" not in heard.read_text(), (state(browser), heard.read_text()[-400:])) # Its cause named by the program, its gesture said, on the page and in the notice (D29). - check("the cause the program named is said with its gesture, on the page and in the notice", - "écrit de compte rendu" in state(browser) and "écrit de compte rendu" in heard.read_text(), + check("the cause the program named is said with its gesture, on the page", + "écrit de compte rendu" in state(browser), (state(browser), heard.read_text()[-400:])) # The developer mode shows what the program said, under the sentence; never in a notice (D29). to_settings() @@ -9094,11 +9236,14 @@ def aside(folder): wait_for(browser, lambda b: b.find_elements(By.ID, "agree-send")) press(browser, "agree-send") # Only what is said after this gesture: a notice may show its title more than once. - told = wait_for(browser, lambda b: "pas été refait" in heard.read_text()[since:], 10) + # Its page in front: the failure said there (below), never by a notification (D92). + ended = wait_for(browser, lambda b: "member=Notify" in heard.read_text()[since:] or b.find_elements(By.ID, "minutes-again"), 10) + time.sleep(1) said = heard.read_text()[since:] monitor.terminate() (WORK / "fail-plainly").unlink() - check("asked through the agreement, still a redo: its failure said as one", told and "pas été fait" not in said and (asked / "minutes.md").read_text() == before, said[-400:]) + check("asked through the agreement, still a redo, its page in front: the ones there stay, nothing notified (D92)", + ended and "member=Notify" not in said and (asked / "minutes.md").read_text() == before, said[-400:]) browser.execute_script("location.hash = '#/'") browser.execute_script("location.hash = '#/meeting/2026-10-18_11-00'") plain = wait_for(browser, lambda b: "n’a pas été fait" in state(b), 5) diff --git a/modules/shell/src/main.rs b/modules/shell/src/main.rs index cf9871db..3ba6d245 100644 --- a/modules/shell/src/main.rs +++ b/modules/shell/src/main.rs @@ -3291,7 +3291,10 @@ fn write_minutes_from( let asked_again = chosen.clone(); drop(writing); shell.minutes_tried.lock().unwrap().insert(folder.clone(), chosen.clone()); - // Not started: said on the meeting's page as well as in a notification (D25). + // Not started: said on the meeting's page, and in a notification (D25) — the one that ends a + // meeting made after a stop, then, its transcript's own not told: its meeting named, and only + // where no window of Kitokey has the focus (D92). + let told = |notice: Notice| tell_made(app, ¬ice, &folder, false); let refused = |why: String| { shell.awaiting.lock().unwrap().retain(|(aside, _)| *aside != folder); shell.minutes_failed.lock().unwrap().insert(folder.clone(), (why, None, None)); @@ -3300,7 +3303,7 @@ fn write_minutes_from( Ok(settings) => settings, Err(why) => { refused(why.detail); - return tell(app, &words::trouble(&Trouble::Settings(why.refused), shell.language())); + return told(words::trouble(&Trouble::Settings(why.refused), shell.language())); } }; let named = settings.minutes_provider.clone().zip(settings.minutes_model.clone()); @@ -3329,7 +3332,7 @@ fn write_minutes_from( let said = words::Minutes::OllamaWaits { silent: wait == Wait::Silent, }; - return tell(app, &words::minutes(&said, shell.language())); + return told(words::minutes(&said, shell.language())); } } } else { @@ -3342,19 +3345,19 @@ fn write_minutes_from( if from_line { return; } - tell(app, &words::minutes(&words::Minutes::Unchosen, shell.language())); + told(words::minutes(&words::Minutes::Unchosen, shell.language())); return open_window_at(app, "#/settings"); } }; if !matches!(meeting::transcript(&folder), meeting::Read::Present(transcript) if transcript.complete) { refused("this meeting has no whole transcript".into()); - return tell(app, &words::minutes(&words::Minutes::NoTranscript, shell.language())); + return told(words::minutes(&words::Minutes::NoTranscript, shell.language())); } let Some(host) = providers::host(&provider) else { let why = format!("{provider} is no provider's address"); tracing::warn!(detail = %why, "shell.minutes_refused"); refused(why); - return tell(app, &words::minutes(&words::Minutes::NoProvider(provider), shell.language())); + return told(words::minutes(&words::Minutes::NoProvider(provider), shell.language())); }; if agreed_now != Some(host.as_str()) && !providers::local(&provider) && settings.minutes_agreed.as_deref() != Some(host.as_str()) { let mut awaiting = shell.awaiting.lock().unwrap(); @@ -3371,7 +3374,7 @@ fn write_minutes_from( if from_line { return; } - tell(app, &words::minutes(&words::Minutes::Waiting(host), shell.language())); + told(words::minutes(&words::Minutes::Waiting(host), shell.language())); let name = folder .file_name() .map(|name| name.to_string_lossy().into_owned()) @@ -3531,12 +3534,9 @@ fn write_minutes_from( summarising::Made::Written(_) => words::Minutes::Ready, summarising::Made::Failed(_, cause) => words::Minutes::failed_by(cause, again, own_model.as_deref(), shell.language()), }; - // Ready, a click opens the meeting (D44); a failure is said as ever. - if written { - tell_opening(&app, &words::minutes(&said, shell.language()), folder.clone()); - } else { - tell(&app, &words::minutes(&said, shell.language())); - } + // Ready, a click opens the meeting (D44); failed, it is said — once, naming the meeting, + // where no window of Kitokey has the focus (D92). + tell_made(&app, &words::minutes(&said, shell.language()), &folder, written); }); } @@ -4046,10 +4046,12 @@ fn retranscribe(app: &AppHandle, folder: PathBuf, again: Again, cancel: Cancel) if cancel.cancelled() { return transcribe_next(&app); } - // Made again and ready, its click opens the meeting as after a stop (D44). + // Made again and ready, its click opens the meeting as after a stop (D44); the minutes + // made after it, theirs alone says it (D92). match &made { - Made::Written(_) => tell_opening(&app, &words::made(&made, shell.language()), folder.clone()), - Made::Failed(_) => tell(&app, &words::made(&made, shell.language())), + Made::Written(_) if minutes_after => {} + Made::Written(_) => tell_made(&app, &words::made(&made, shell.language()), &folder, true), + Made::Failed(_) => tell_made(&app, &words::made(&made, shell.language()), &folder, false), } if let Some((name, not_put_back)) = kept_beside { tell(&app, &words::transcript_kept_beside(shell.language(), &name, not_put_back)); @@ -4149,8 +4151,9 @@ fn transcribe(app: &AppHandle, folder: PathBuf, cancel: Cancel) { .transcripts_failed .lock() .unwrap() - .insert(folder, format!("{} is no model on this computer", model.display())); - tell(app, &words::trouble(&trouble, shell.language())); + .insert(folder.clone(), format!("{} is no model on this computer", model.display())); + // The meeting's last step, failed: told as its end is (D92). + tell_made(app, &words::trouble(&trouble, shell.language()), &folder, false); } return; } @@ -4166,9 +4169,9 @@ fn transcribe(app: &AppHandle, folder: PathBuf, cancel: Cancel) { let (transcription, made) = match started { Ok(started) => started, Err(error) => { - shell.transcripts_failed.lock().unwrap().insert(folder, error.to_string()); - tell(app, &words::trouble(&Trouble::NoTranscriber(error.to_string()), shell.language())); - return; + shell.transcripts_failed.lock().unwrap().insert(folder.clone(), error.to_string()); + let notice = words::trouble(&Trouble::NoTranscriber(error.to_string()), shell.language()); + return tell_made(app, ¬ice, &folder, false); } }; // Held by its token: cancelled meanwhile, it is stopped at once (D92). @@ -4210,14 +4213,14 @@ fn transcribe(app: &AppHandle, folder: PathBuf, cancel: Cancel) { match made { Made::Written(folder) => { // The minutes follow, when the settings say so — as they are now; then their - // notification alone says the meeting is made (D44). + // notification alone says the meeting is made (D44, D92). if shell.reread().is_ok_and(|settings| settings.after == settings::After::Minutes) { make_minutes(&app, folder); } else { - tell_opening(&app, ¬ice, folder.clone()); + tell_made(&app, ¬ice, &folder, true); } } - Made::Failed(_) => tell(&app, ¬ice), + Made::Failed(_) => tell_made(&app, ¬ice, &heard_folder, false), } transcribe_next(&app); }); @@ -4576,6 +4579,40 @@ fn window_seen(app: &AppHandle) -> bool { .any(|window| window.is_visible().unwrap_or(false) && !window.is_minimized().unwrap_or(false)) } +/// Whether a window of Kitokey has the focus, as the toolkit says: the user is in Kitokey (D92). +fn window_focused(app: &AppHandle) -> bool { + ["main", "small"] + .iter() + .filter_map(|label| app.get_webview_window(label)) + .any(|window| window.is_focused().unwrap_or(false)) +} + +/// A notice about a meeting, its meeting named first: its title, else when it was recorded (D92). +fn of_meeting(app: &AppHandle, notice: &Notice, folder: &Path) -> Notice { + let language = app.state::().language(); + let name = folder.file_name().unwrap_or_default().to_string_lossy(); + let title = named::read(folder).or_else(|| minutes::title(folder)); + let started = chrono::NaiveDateTime::parse_from_str(&name, "%Y-%m-%d_%H-%M").ok(); + let meeting = words::meeting(title.as_deref(), started, chrono::Local::now().date_naive(), language); + words::for_meeting(notice.clone(), &meeting, language) +} + +/// The notification that ends a meeting's making — its last step written or failed, or the next +/// one unable to start (D25) —: told naming the meeting, and only when no window of Kitokey has the +/// focus, the window saying it there (D92). `opening`: its click opens the meeting (D44). +fn tell_made(app: &AppHandle, notice: &Notice, folder: &Path, opening: bool) { + if window_focused(app) { + tracing::info!("shell.made_not_told"); + return; + } + let notice = of_meeting(app, notice, folder); + if opening { + tell_opening(app, ¬ice, folder.to_path_buf()); + } else { + tell(app, ¬ice); + } +} + /// Quits Kitokey. A recording in progress is stopped first, as the user would stop it: its /// files are whole before Kitokey is gone. Asked a second time, Kitokey leaves at once: a /// recorder that does not end is not a reason to keep the user. diff --git a/modules/shell/src/words.rs b/modules/shell/src/words.rs index 6841df61..bdc846d2 100644 --- a/modules/shell/src/words.rs +++ b/modules/shell/src/words.rs @@ -64,6 +64,81 @@ pub struct Notice { pub body: String, } +/// A day as the window's `Intl` says it, with CLDR's abbreviated months: « 18 oct. », "Oct 18". +/// One formatter for every day Kitokey says beside a meeting (D92, D93). +pub fn day(day: chrono::NaiveDate, language: Language) -> String { + // Shows: in a notification's body, the day a meeting was recorded. When: a meeting is named by + // its day and hour, not recorded today. At most: no limit. Placeholders: none. + use chrono::Datelike; + // CLDR's abbreviated months, as `Intl.DateTimeFormat` gives them with `month: "short"`. + let month = day.month0() as usize; + match language { + Language::English => { + let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + format!("{} {}", months[month], day.day()) + } + Language::French => { + let months = [ + "janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.", + ]; + format!("{} {}", day.day(), months[month]) + } + } +} + +/// An hour as the window's `Intl` says it, two digits: « 09:42 », "09:42 AM". +pub fn hour(time: chrono::NaiveTime, language: Language) -> String { + // Shows: in a notification's body, the hour a meeting was recorded. When: a meeting is named by + // its hour. At most: no limit. Placeholders: none. + match language { + Language::English => time.format("%I:%M %p").to_string(), + // `%R`: the hour and minutes on 24 hours, as `%H:%M`. + Language::French => time.format("%R").to_string(), + } +} + +/// A meeting named in a sentence (D92): the title it was given, else when it was recorded — its +/// hour on the day it is said, its day and hour after. Used where a sentence names the meeting it +/// is about; the window names it in its list and page itself. +pub fn meeting(title: Option<&str>, started: Option, today: chrono::NaiveDate, language: Language) -> String { + // Shows: in a notification's body, the meeting it is about. When: a meeting is named, without a + // title of its own. At most: no limit. Placeholders: {} its hour, or its day then its hour. + use Language::{English, French}; + match (title.map(str::trim).filter(|title| !title.is_empty()), started, language) { + (Some(title), _, French) => format!("«\u{a0}{title}\u{a0}»"), + (Some(title), _, English) => format!("“{title}”"), + (None, Some(started), French) if started.date() == today => format!("la réunion de {}", hour(started.time(), French)), + (None, Some(started), English) if started.date() == today => format!("the {} meeting", hour(started.time(), English)), + (None, Some(started), French) => { + format!("la réunion du {} à {}", day(started.date(), French), hour(started.time(), French)) + } + (None, Some(started), English) => { + format!( + "the meeting of {} at {}", + day(started.date(), English), + hour(started.time(), English) + ) + } + (None, None, French) => "la réunion".into(), + (None, None, English) => "the meeting".into(), + } +} + +/// The notification that ends a meeting's making, its meeting named first (D92). +pub fn for_meeting(notice: Notice, meeting: &str, language: Language) -> Notice { + // Shows: a notification's body, before the sentences it had. When: the meeting's last step + // ended — written or failed —, no window of Kitokey having the focus. At most: no limit. + // Placeholders: {meeting} the meeting, as `meeting` names it. + let named = match language { + Language::French => format!("Pour {meeting}."), + Language::English => format!("For {meeting}."), + }; + Notice { + body: format!("{named} {}", notice.body), + ..notice + } +} + /// A length as a person says it: seconds under a minute, then minutes, then hours — each /// to the nearest, so that a minute and fifty-nine seconds is two minutes. pub fn length(seconds: f64) -> String { diff --git a/modules/shell/tests/words.rs b/modules/shell/tests/words.rs index f193788d..de18e2af 100644 --- a/modules/shell/tests/words.rs +++ b/modules/shell/tests/words.rs @@ -2233,6 +2233,87 @@ fn a_notice_of_minutes_failed_by_the_meetings_own_model_says_what_its_page_says( } } +/// A meeting's day and hour, as the window's `Intl` says them (CLDR's abbreviated months). +fn at(day: &str, time: &str) -> chrono::NaiveDateTime { + chrono::NaiveDateTime::parse_from_str(&format!("{day} {time}"), "%Y-%m-%d %H:%M").unwrap() +} + +#[test] +fn a_day_and_an_hour_are_said_as_the_window_says_them() { + let french = [ + "janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.", + ]; + let english = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + for (month, (fr, en)) in french.iter().zip(english).enumerate() { + let day = chrono::NaiveDate::from_ymd_opt(2026, month as u32 + 1, 18).unwrap(); + assert_eq!(words::day(day, Language::French), format!("18 {fr}")); + assert_eq!(words::day(day, Language::English), format!("{en} 18")); + } + let first = chrono::NaiveDate::from_ymd_opt(2026, 11, 1).unwrap(); + assert_eq!( + (words::day(first, Language::French), words::day(first, Language::English)), + ("1 nov.".into(), "Nov 1".into()) + ); + for (time, fr, en) in [ + ("12:00", "12:00", "12:00 PM"), + ("09:42", "09:42", "09:42 AM"), + ("00:05", "00:05", "12:05 AM"), + ("17:31", "17:31", "05:31 PM"), + ] { + let when = at("2026-11-13", time); + assert_eq!(words::hour(when.time(), Language::French), fr); + assert_eq!(words::hour(when.time(), Language::English), en); + } +} + +#[test] +fn a_meeting_is_named_by_its_title_else_its_hour_that_day_else_its_day_and_hour() { + let started = Some(at("2026-10-18", "12:00")); + let (that_day, later) = (at("2026-10-18", "23:59").date(), at("2026-11-14", "01:00").date()); + let named = |title, when, today, language| words::meeting(title, when, today, language); + assert_eq!( + named(Some("Point hebdo"), started, later, Language::French), + "«\u{a0}Point hebdo\u{a0}»" + ); + assert_eq!(named(Some("Weekly sync"), started, later, Language::English), "“Weekly sync”"); + assert_eq!(named(None, started, that_day, Language::French), "la réunion de 12:00"); + assert_eq!(named(None, started, that_day, Language::English), "the 12:00 PM meeting"); + assert_eq!(named(None, started, later, Language::French), "la réunion du 18 oct. à 12:00"); + assert_eq!(named(None, started, later, Language::English), "the meeting of Oct 18 at 12:00 PM"); + // A title of blanks is none; a meeting whose start cannot be read is the meeting. + assert_eq!( + named(Some(" \t"), started, later, Language::French), + "la réunion du 18 oct. à 12:00" + ); + assert_eq!(named(None, None, later, Language::French), "la réunion"); + assert_eq!(named(None, None, later, Language::English), "the meeting"); +} + +#[test] +fn the_notification_that_ends_a_meeting_names_it_first_and_keeps_its_title() { + for language in BOTH { + let notice = words::minutes(&words::Minutes::Ready, language); + let meeting = words::meeting(None, Some(at("2026-10-18", "12:00")), at("2026-11-14", "01:00").date(), language); + let told = words::for_meeting(notice.clone(), &meeting, language); + assert_eq!(told.title, notice.title); + assert!(told.body.ends_with(¬ice.body), "{told:?}"); + assert!(told.body.contains(&meeting), "{told:?}"); + assert!(told.title.chars().count() <= 50, "{told:?}"); + } + let told = words::for_meeting( + words::minutes(&words::Minutes::Ready, Language::French), + "«\u{a0}Point hebdo\u{a0}»", + Language::French, + ); + assert!(told.body.starts_with("Pour «\u{a0}Point hebdo\u{a0}». "), "{told:?}"); + let told = words::for_meeting( + words::minutes(&words::Minutes::Ready, Language::English), + "the 12:00 PM meeting", + Language::English, + ); + assert!(told.body.starts_with("For the 12:00 PM meeting. "), "{told:?}"); +} + /// A settings file refused is said in the user's language: which setting, on which line, and what /// to do — never `settings.rs`'s own sentence, which stays for the log and behind « Développeur » /// (#783, D94). The window says it under each command it refuses, and the notification at a start. @@ -2319,7 +2400,8 @@ const TITLES_TOO_LONG: [&str; 2] = [ /// The functions of `words.rs` that return a notification, each read below: one added there fails /// the title's test until it is named here — and read in `every_notice`, which the review checks. -const NOTIFYING: [&str; 17] = [ +const NOTIFYING: [&str; 18] = [ + "for_meeting", "of", "notice", "trouble", @@ -2513,6 +2595,12 @@ fn every_notice(language: Language) -> Vec { notices.push(words::fetched(&outcome, chosen, language)); } } + // Each one sent again with its meeting named first (D92): its title kept. + let named: Vec<_> = notices + .iter() + .map(|notice| words::for_meeting(notice.clone(), "x", language)) + .collect(); + notices.extend(named); notices }