@opengeni/desktop 6.8.0 → 6.8.1-canary.41842879332001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,9 +8,9 @@ var __export = (target, all) => {
8
8
  };
9
9
  var __copyProps = (to, from, except, desc) => {
10
10
  if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ for (let key2 of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
13
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
14
14
  }
15
15
  return to;
16
16
  };
@@ -1532,9 +1532,9 @@ function parseVocabulary(value) {
1532
1532
  for (const item of value) {
1533
1533
  if (typeof item !== "string") continue;
1534
1534
  const term = item.trim().replace(/\s+/gu, " ");
1535
- const key = term.toLocaleLowerCase();
1536
- if (!term || term.length > DICTATION_VOCABULARY_TERM_MAX || seen.has(key)) continue;
1537
- seen.add(key);
1535
+ const key2 = term.toLocaleLowerCase();
1536
+ if (!term || term.length > DICTATION_VOCABULARY_TERM_MAX || seen.has(key2)) continue;
1537
+ seen.add(key2);
1538
1538
  terms.push(term);
1539
1539
  if (terms.length === DICTATION_VOCABULARY_MAX) break;
1540
1540
  }
@@ -1594,10 +1594,10 @@ function mergeDictationSettings(current, change) {
1594
1594
  );
1595
1595
  if (valid) profiles = parsed;
1596
1596
  }
1597
- const keys = (key) => {
1598
- const kept = current[key] ?? null;
1599
- if (!(key in candidate)) return kept;
1600
- const value = candidate[key];
1597
+ const keys = (key2) => {
1598
+ const kept = current[key2] ?? null;
1599
+ if (!(key2 in candidate)) return kept;
1600
+ const value = candidate[key2];
1601
1601
  return value === null ? null : parseKeys(value) ?? kept;
1602
1602
  };
1603
1603
  let retryShortcut = keys("retryShortcut");
@@ -1884,7 +1884,7 @@ function macKeyWatchArgument(watches) {
1884
1884
  watches.map(
1885
1885
  (watch) => watch.shortcut.kind === "modifierPair" ? { id: watch.id, pair: PAIR_MASKS[watch.shortcut.modifier] } : {
1886
1886
  id: watch.id,
1887
- chord: watch.shortcut.modifiers.reduce((mask, key) => mask | CHORD_MASKS[key], 0)
1887
+ chord: watch.shortcut.modifiers.reduce((mask, key2) => mask | CHORD_MASKS[key2], 0)
1888
1888
  }
1889
1889
  )
1890
1890
  );
@@ -2786,9 +2786,9 @@ var Dictation = class {
2786
2786
  /** Tell the menu bar when the activity is not what it last heard. */
2787
2787
  activityChanged() {
2788
2788
  const activity = this.activity();
2789
- const key = JSON.stringify(activity);
2790
- if (key === this.lastActivity) return;
2791
- this.lastActivity = key;
2789
+ const key2 = JSON.stringify(activity);
2790
+ if (key2 === this.lastActivity) return;
2791
+ this.lastActivity = key2;
2792
2792
  this.tellActivity(activity);
2793
2793
  }
2794
2794
  tellActivity(activity) {
@@ -3140,8 +3140,8 @@ function mergeComputerSettings(current, change) {
3140
3140
  if (!change || typeof change !== "object") return current;
3141
3141
  const candidate = change;
3142
3142
  const next = { ...current };
3143
- for (const key of SETTING_KEYS) {
3144
- if (typeof candidate[key] === "boolean") next[key] = candidate[key];
3143
+ for (const key2 of SETTING_KEYS) {
3144
+ if (typeof candidate[key2] === "boolean") next[key2] = candidate[key2];
3145
3145
  }
3146
3146
  return next;
3147
3147
  }
@@ -3214,7 +3214,7 @@ var ComputerCapabilities = class {
3214
3214
  } catch (caught) {
3215
3215
  deps.log?.("Couldn't read what Opengeni may do on this computer", caught);
3216
3216
  this.settings = { ...UNREADABLE_COMPUTER_SETTINGS };
3217
- for (const key of SETTING_KEYS) this.problems[key] = UNREADABLE_PROBLEM;
3217
+ for (const key2 of SETTING_KEYS) this.problems[key2] = UNREADABLE_PROBLEM;
3218
3218
  }
3219
3219
  }
3220
3220
  settings;
@@ -3246,7 +3246,7 @@ var ComputerCapabilities = class {
3246
3246
  reason = null;
3247
3247
  }
3248
3248
  if (reason) {
3249
- for (const key of unavailable) problems[key] ??= reason;
3249
+ for (const key2 of unavailable) problems[key2] ??= reason;
3250
3250
  }
3251
3251
  if (!unavailable.includes("screenControl") && this.deps.screenControlSwitch) {
3252
3252
  const honoured = await this.deps.screenControlSwitch().catch(() => null);
@@ -3272,27 +3272,27 @@ var ComputerCapabilities = class {
3272
3272
  async update(change) {
3273
3273
  const unavailable = new Set((await this.status()).unavailable);
3274
3274
  const next = { ...mergeComputerSettings(this.settings, change) };
3275
- for (const key of unavailable) next[key] = this.settings[key];
3276
- const changed = SETTING_KEYS.filter((key) => next[key] !== this.settings[key]);
3275
+ for (const key2 of unavailable) next[key2] = this.settings[key2];
3276
+ const changed = SETTING_KEYS.filter((key2) => next[key2] !== this.settings[key2]);
3277
3277
  if (changed.length === 0) return this.status();
3278
3278
  this.settings = next;
3279
- for (const key of changed) delete this.problems[key];
3279
+ for (const key2 of changed) delete this.problems[key2];
3280
3280
  try {
3281
3281
  this.deps.store.write(next);
3282
3282
  } catch (caught) {
3283
3283
  this.deps.log?.("Couldn't save what Opengeni may do on this computer", caught);
3284
- for (const key of changed) this.problems[key] = UNSAVED_PROBLEM;
3284
+ for (const key2 of changed) this.problems[key2] = UNSAVED_PROBLEM;
3285
3285
  }
3286
3286
  this.deps.onChange();
3287
- const agentKeys = changed.filter((key) => key !== "microphone");
3287
+ const agentKeys = changed.filter((key2) => key2 !== "microphone");
3288
3288
  if (agentKeys.length > 0) {
3289
3289
  try {
3290
3290
  await this.deps.agentSwitchesChanged();
3291
3291
  } catch (caught) {
3292
3292
  this.deps.log?.("Couldn't restart this computer's agent", caught);
3293
3293
  const reason = caught instanceof Error && caught.message ? ` ${caught.message}` : "";
3294
- for (const key of agentKeys) {
3295
- this.problems[key] = `Couldn't restart the agent with this change.${reason}`;
3294
+ for (const key2 of agentKeys) {
3295
+ this.problems[key2] = `Couldn't restart the agent with this change.${reason}`;
3296
3296
  }
3297
3297
  this.deps.onChange();
3298
3298
  }
@@ -3921,12 +3921,269 @@ var ENGLISH_MEETING_WORDS = {
3921
3921
  keepRecording: "Keep recording",
3922
3922
  recordingStarted: "Recording this call",
3923
3923
  callRecording: "A call in {app} started, so it's being recorded.",
3924
- ok: "OK"
3924
+ ok: "OK",
3925
+ startsIn: "Starts in {minutes} min",
3926
+ startingNow: "Starting now",
3927
+ startedAgo: "Started {minutes} min ago",
3928
+ untitledMeeting: "Meeting",
3929
+ reminderTitle: "Upcoming meeting",
3930
+ joinAndStart: "Join and start recording",
3931
+ joinAndSwitch: "Join and record this one"
3925
3932
  };
3926
3933
  function fillMeetingWords(template, values) {
3927
3934
  return template.replace(/\{(\w+)\}/g, (match, name) => values[name] ?? match);
3928
3935
  }
3929
3936
 
3937
+ // src/main/meeting-detection/reminders.ts
3938
+ var REMIND_BEFORE_MS = 6e4;
3939
+ var JOIN_LATE_MS = 5 * 6e4;
3940
+ var POLL_MS2 = 5 * 6e4;
3941
+ var POLL_SOON_MS = 6e4;
3942
+ var SOON_MS = 3 * 6e4;
3943
+ var EARLY_JOIN_MS = 10 * 6e4;
3944
+ var REMINDER_TICK_MS = 15e3;
3945
+ var MIN_CARD_MS = 3e4;
3946
+ var RECHECK_CALENDAR_MS = 3e4;
3947
+ function isHttpsUrl(value) {
3948
+ if (typeof value !== "string" || value.length > 2048) return false;
3949
+ try {
3950
+ return new URL(value).protocol === "https:";
3951
+ } catch {
3952
+ return false;
3953
+ }
3954
+ }
3955
+ function time(value) {
3956
+ if (typeof value !== "string") return null;
3957
+ const parsed = Date.parse(value);
3958
+ return Number.isNaN(parsed) ? null : parsed;
3959
+ }
3960
+ function parseUpcomingMeetings(body) {
3961
+ if (!body || typeof body !== "object") return null;
3962
+ const value = body;
3963
+ if (value.calendar !== "connected" && value.calendar !== "none") return null;
3964
+ const meetings = [];
3965
+ for (const entry of Array.isArray(value.meetings) ? value.meetings : []) {
3966
+ if (!entry || typeof entry !== "object") continue;
3967
+ const meeting = entry;
3968
+ const startsAt = time(meeting.startsAt);
3969
+ const endsAt = time(meeting.endsAt);
3970
+ if (typeof meeting.id !== "string" || !meeting.id || meeting.provider !== "google" && meeting.provider !== "microsoft" || startsAt === null || endsAt === null || !isHttpsUrl(meeting.joinUrl)) {
3971
+ continue;
3972
+ }
3973
+ meetings.push({
3974
+ id: meeting.id,
3975
+ provider: meeting.provider,
3976
+ title: typeof meeting.title === "string" ? meeting.title.trim().slice(0, 300) : "",
3977
+ private: meeting.private === true,
3978
+ startsAt,
3979
+ endsAt,
3980
+ joinUrl: meeting.joinUrl,
3981
+ service: typeof meeting.service === "string" && meeting.service.trim() ? meeting.service.trim().slice(0, 60) : "Meeting"
3982
+ });
3983
+ }
3984
+ meetings.sort((a, b) => a.startsAt - b.startsAt);
3985
+ return { calendar: value.calendar, complete: value.complete !== false, meetings };
3986
+ }
3987
+ function key(accountId, meeting) {
3988
+ return `${accountId}|${meeting.provider}|${meeting.id}|${meeting.startsAt}`;
3989
+ }
3990
+ function reminderDue(meeting, now) {
3991
+ return meeting.startsAt - now <= REMIND_BEFORE_MS && now - meeting.startsAt < JOIN_LATE_MS && now < meeting.endsAt;
3992
+ }
3993
+ var CalendarReminders = class {
3994
+ constructor(options) {
3995
+ this.options = options;
3996
+ }
3997
+ timer = null;
3998
+ accountId = null;
3999
+ upcoming = null;
4000
+ fetchedAt = 0;
4001
+ fetching = null;
4002
+ /** Bumped when the account changes, so a read for the one before is ignored. */
4003
+ generation = 0;
4004
+ offered = /* @__PURE__ */ new Set();
4005
+ shown = null;
4006
+ get running() {
4007
+ return this.timer !== null;
4008
+ }
4009
+ /** The active account's calendar, as last read: null before the first read. */
4010
+ calendar() {
4011
+ return this.upcoming?.calendar ?? null;
4012
+ }
4013
+ start() {
4014
+ if (this.timer) return;
4015
+ this.timer = setInterval(() => this.tick(), REMINDER_TICK_MS);
4016
+ this.timer.unref?.();
4017
+ this.tick();
4018
+ }
4019
+ stop() {
4020
+ if (this.timer) clearInterval(this.timer);
4021
+ this.timer = null;
4022
+ this.generation += 1;
4023
+ this.close();
4024
+ }
4025
+ /** Read the calendar at the next tick, e.g. after the computer wakes. */
4026
+ refresh() {
4027
+ this.fetchedAt = 0;
4028
+ if (this.timer) this.tick();
4029
+ }
4030
+ /**
4031
+ * The person may have just connected a calendar (an app window came to the
4032
+ * front): read again soon, while there is none, so settings stop offering it.
4033
+ */
4034
+ recheckCalendar() {
4035
+ if (this.upcoming?.calendar !== "none") return;
4036
+ if (this.now() - this.fetchedAt < RECHECK_CALENDAR_MS) return;
4037
+ this.refresh();
4038
+ }
4039
+ /** The active account may have changed: its card goes, and the new one's calendar is read. */
4040
+ accountChanged() {
4041
+ const id = this.options.account()?.id ?? null;
4042
+ if (id === this.accountId) return;
4043
+ this.generation += 1;
4044
+ this.accountId = id;
4045
+ this.upcoming = null;
4046
+ this.fetchedAt = 0;
4047
+ this.close();
4048
+ this.options.onCalendar?.(null);
4049
+ if (this.timer) this.tick();
4050
+ }
4051
+ /** Run about every {@link REMINDER_TICK_MS}: read the calendar when it's time, then decide. */
4052
+ tick() {
4053
+ const now = this.now();
4054
+ if (!this.options.enabled()) {
4055
+ this.close();
4056
+ return;
4057
+ }
4058
+ this.accountChanged();
4059
+ if (this.accountId && !this.fetching && now - this.fetchedAt >= this.pollInterval(now)) {
4060
+ void this.read(this.accountId);
4061
+ }
4062
+ this.evaluate(now);
4063
+ }
4064
+ /** Show, keep or take back the card for what the calendar says at `now`. */
4065
+ evaluate(now) {
4066
+ const accountId = this.accountId;
4067
+ if (!this.timer || !this.options.enabled() || !accountId || !this.upcoming) {
4068
+ this.close();
4069
+ return;
4070
+ }
4071
+ const meetings = this.upcoming.meetings;
4072
+ if (this.shown) {
4073
+ const still = meetings.some((meeting2) => key(accountId, meeting2) === this.shown?.key);
4074
+ if (!still) this.close();
4075
+ return;
4076
+ }
4077
+ if (this.options.busy()) return;
4078
+ const since = this.options.recordingSince();
4079
+ const due = meetings.filter(
4080
+ (meeting2) => reminderDue(meeting2, now) && !this.offered.has(key(accountId, meeting2)) && // Recording since just before it started: the person joined it early.
4081
+ !(since !== null && since >= meeting2.startsAt - EARLY_JOIN_MS)
4082
+ );
4083
+ const meeting = due[0];
4084
+ if (!meeting) return;
4085
+ const reminder = {
4086
+ accountId,
4087
+ meeting,
4088
+ replace: since !== null,
4089
+ shownAt: now,
4090
+ timeoutMs: Math.max(MIN_CARD_MS, meeting.startsAt + JOIN_LATE_MS - now)
4091
+ };
4092
+ const shownKey = key(accountId, meeting);
4093
+ this.options.log(`Meeting reminders: offered a meeting (${meeting.provider}).`);
4094
+ let open = true;
4095
+ const handle = this.options.present(reminder, (outcome) => {
4096
+ if (!open) return;
4097
+ open = false;
4098
+ if (this.shown?.key === shownKey) this.shown = null;
4099
+ for (const other of this.upcoming?.meetings ?? []) {
4100
+ if (reminderDue(other, this.now())) this.remember(key(accountId, other));
4101
+ }
4102
+ this.remember(shownKey);
4103
+ this.options.log(`Meeting reminders: ${OUTCOMES[outcome]}.`);
4104
+ if (outcome === "chosen") {
4105
+ if (this.options.account()?.id !== accountId) {
4106
+ this.options.log("Meeting reminders: the account changed; not joining.");
4107
+ return;
4108
+ }
4109
+ this.options.join(reminder);
4110
+ }
4111
+ });
4112
+ this.shown = {
4113
+ key: shownKey,
4114
+ reminder,
4115
+ handle: {
4116
+ close: () => {
4117
+ if (!open) return;
4118
+ open = false;
4119
+ this.remember(shownKey);
4120
+ handle.close();
4121
+ }
4122
+ }
4123
+ };
4124
+ }
4125
+ /** The reminder on the card, if any. */
4126
+ showing() {
4127
+ return this.shown?.reminder ?? null;
4128
+ }
4129
+ pollInterval(now) {
4130
+ const accountId = this.accountId;
4131
+ const soon = (this.upcoming?.meetings ?? []).some(
4132
+ (meeting) => accountId !== null && !this.offered.has(key(accountId, meeting)) && meeting.startsAt - REMIND_BEFORE_MS - now <= SOON_MS && now - meeting.startsAt < JOIN_LATE_MS
4133
+ );
4134
+ return soon ? POLL_SOON_MS : POLL_MS2;
4135
+ }
4136
+ read(accountId) {
4137
+ const generation = this.generation;
4138
+ this.fetchedAt = this.now();
4139
+ this.fetching = (async () => {
4140
+ let upcoming = null;
4141
+ try {
4142
+ upcoming = await this.options.upcoming(accountId);
4143
+ } catch (error) {
4144
+ this.options.log("Meeting reminders: couldn't read the calendar.", error);
4145
+ }
4146
+ if (generation !== this.generation || upcoming === null) return;
4147
+ const before = this.upcoming?.calendar ?? null;
4148
+ const known = this.upcoming;
4149
+ if (!upcoming.complete && known) {
4150
+ const listed = new Set(upcoming.meetings.map((meeting) => key(accountId, meeting)));
4151
+ const kept = known.meetings.filter((meeting) => !listed.has(key(accountId, meeting)));
4152
+ upcoming = {
4153
+ ...upcoming,
4154
+ meetings: [...upcoming.meetings, ...kept].sort((a, b) => a.startsAt - b.startsAt)
4155
+ };
4156
+ }
4157
+ this.upcoming = upcoming;
4158
+ if (before !== upcoming.calendar) this.options.onCalendar?.(upcoming.calendar);
4159
+ this.evaluate(this.now());
4160
+ })().finally(() => {
4161
+ this.fetching = null;
4162
+ });
4163
+ return this.fetching;
4164
+ }
4165
+ remember(offeredKey) {
4166
+ this.offered.add(offeredKey);
4167
+ if (this.offered.size > 500) {
4168
+ const oldest = this.offered.values().next().value;
4169
+ if (oldest !== void 0) this.offered.delete(oldest);
4170
+ }
4171
+ }
4172
+ close() {
4173
+ const shown = this.shown;
4174
+ this.shown = null;
4175
+ shown?.handle.close();
4176
+ }
4177
+ now() {
4178
+ return (this.options.now ?? Date.now)();
4179
+ }
4180
+ };
4181
+ var OUTCOMES = {
4182
+ chosen: "the person chose to join",
4183
+ dismissed: "the person closed the reminder",
4184
+ expired: "the reminder timed out"
4185
+ };
4186
+
3930
4187
  // src/main/meeting-detection/index.ts
3931
4188
  var KNOWN_APPS = [
3932
4189
  {
@@ -4132,6 +4389,14 @@ function parseWatchLine(line) {
4132
4389
  }
4133
4390
  var PROMPT_AFTER_MS = 3e3;
4134
4391
  var ENDED_AFTER_MS = 8e3;
4392
+ function joinPrompt(reminder) {
4393
+ const service = reminder.meeting.service;
4394
+ return {
4395
+ kind: "join",
4396
+ app: { id: "calendar", name: service, browser: false, title: service },
4397
+ reminder
4398
+ };
4399
+ }
4135
4400
  var AUTO_START_WAIT_MS = 6e4;
4136
4401
  var MeetingPrompter = class {
4137
4402
  constructor(own, show, auto = null) {
@@ -4249,7 +4514,30 @@ var MeetingPrompter = class {
4249
4514
  shown?.handle.close();
4250
4515
  }
4251
4516
  };
4517
+ function startsWhen(meeting, at, words) {
4518
+ const english = ENGLISH_MEETING_WORDS;
4519
+ const left = meeting.startsAt - at;
4520
+ if (left > 3e4) {
4521
+ return fillMeetingWords(words.startsIn ?? english.startsIn, {
4522
+ minutes: String(Math.max(1, Math.round(left / 6e4)))
4523
+ });
4524
+ }
4525
+ if (left > -6e4) return words.startingNow ?? english.startingNow;
4526
+ return fillMeetingWords(words.startedAgo ?? english.startedAgo, {
4527
+ minutes: String(Math.floor(-left / 6e4))
4528
+ });
4529
+ }
4252
4530
  function promptText(prompt, words = ENGLISH_MEETING_WORDS) {
4531
+ if (prompt.kind === "join") {
4532
+ const { meeting, replace, shownAt } = prompt.reminder;
4533
+ const english = ENGLISH_MEETING_WORDS;
4534
+ return {
4535
+ question: meeting.title || (words.untitledMeeting ?? english.untitledMeeting),
4536
+ reason: `${startsWhen(meeting, shownAt, words)} \xB7 ${meeting.service}`,
4537
+ action: replace ? words.joinAndSwitch ?? english.joinAndSwitch : words.joinAndStart ?? english.joinAndStart,
4538
+ dismiss: words.notNow
4539
+ };
4540
+ }
4253
4541
  const values = { app: prompt.app.name };
4254
4542
  if (prompt.kind === "record") {
4255
4543
  return {
@@ -4278,6 +4566,16 @@ function promptText(prompt, words = ENGLISH_MEETING_WORDS) {
4278
4566
  };
4279
4567
  }
4280
4568
  function promptRequest(prompt) {
4569
+ if (prompt.kind === "join") {
4570
+ const { meeting, replace } = prompt.reminder;
4571
+ return {
4572
+ kind: "record",
4573
+ app: meeting.service,
4574
+ title: meeting.private || !meeting.title ? meeting.service : meeting.title,
4575
+ calendarEvent: { provider: meeting.provider, id: meeting.id },
4576
+ ...replace ? { replace: true } : {}
4577
+ };
4578
+ }
4281
4579
  return prompt.kind === "record" ? { kind: "record", app: prompt.app.name, title: prompt.app.title } : { kind: "stop", app: prompt.app.name };
4282
4580
  }
4283
4581
  var MeetingDetectionStore = class {
@@ -4297,6 +4595,13 @@ var MeetingDetectionStore = class {
4297
4595
  setAutoRecord(autoRecord) {
4298
4596
  this.write({ ...this.file(), recordCallsWithoutAsking: autoRecord });
4299
4597
  }
4598
+ /** Reminders before calendar meetings: on unless turned off. */
4599
+ calendarReminders() {
4600
+ return this.file().remindBeforeMeetings !== false;
4601
+ }
4602
+ setCalendarReminders(on) {
4603
+ this.write({ ...this.file(), remindBeforeMeetings: on });
4604
+ }
4300
4605
  canRecord() {
4301
4606
  return this.file().canRecord === true;
4302
4607
  }
@@ -4350,6 +4655,29 @@ var MeetingDetection = class {
4350
4655
  this.deliver(promptRequest({ kind: "stop", app: app4 }), { quiet: true });
4351
4656
  }
4352
4657
  });
4658
+ const calendar = options.calendar;
4659
+ this.reminders = calendar ? new CalendarReminders({
4660
+ account: () => calendar.account(),
4661
+ upcoming: async (accountId) => parseUpcomingMeetings(await calendar.upcoming(accountId)),
4662
+ enabled: () => this.remindersWanted(),
4663
+ // Only a recording in the account the meeting would record in is
4664
+ // switched; one in another account goes on.
4665
+ recordingSince: () => this.targetRecords() ? this.recordingSince : null,
4666
+ // A call that just started, or one that ended, is asked about first.
4667
+ busy: () => this.onCard?.prompt.kind === "record" || this.onCard?.prompt.kind === "stop",
4668
+ present: (reminder, done) => this.showCard(joinPrompt(reminder), done),
4669
+ join: (reminder) => {
4670
+ this.deliver(promptRequest(joinPrompt(reminder)), { quiet: true });
4671
+ try {
4672
+ calendar.openUrl(reminder.meeting.joinUrl);
4673
+ } catch (error) {
4674
+ this.options.log("Meeting reminders: couldn't open the meeting's link.", error);
4675
+ }
4676
+ },
4677
+ onCalendar: () => this.changed(),
4678
+ log: (message, error) => this.options.log(message, error),
4679
+ ...options.now ? { now: options.now } : {}
4680
+ }) : null;
4353
4681
  }
4354
4682
  prompter;
4355
4683
  child = null;
@@ -4366,16 +4694,39 @@ var MeetingDetection = class {
4366
4694
  recordingListeners = /* @__PURE__ */ new Set();
4367
4695
  pending = null;
4368
4696
  cannotRecord = null;
4697
+ reminders;
4698
+ /** Since when a page here records, or null. */
4699
+ recordingSince = null;
4700
+ /** The card's current question, and what to do when another takes its place. */
4701
+ onCard = null;
4369
4702
  status() {
4703
+ const calendar = this.reminders?.calendar() ?? null;
4370
4704
  return {
4371
4705
  enabled: this.options.store.enabled(),
4372
4706
  autoRecord: this.autoRecord(),
4373
4707
  available: this.usable(),
4708
+ ...this.reminders ? { calendarReminders: this.calendarRemindersOn() } : {},
4709
+ ...this.reminders && calendar ? { calendar } : {},
4374
4710
  ...this.problem ? { problem: this.problem } : {}
4375
4711
  };
4376
4712
  }
4713
+ /**
4714
+ * The active account may have changed: a reminder for the one before goes,
4715
+ * and the new one's calendar is read. Call it whenever accounts change.
4716
+ */
4717
+ accountChanged() {
4718
+ this.reminders?.accountChanged();
4719
+ }
4720
+ /** Read the calendar again soon, e.g. after the computer wakes. */
4721
+ refreshCalendar() {
4722
+ this.reminders?.refresh();
4723
+ }
4724
+ /** An app window came to the front: without a calendar, check whether one was just connected. */
4725
+ windowFocused() {
4726
+ this.reminders?.recheckCalendar();
4727
+ }
4377
4728
  update(change) {
4378
- const { enabled, autoRecord } = change && typeof change === "object" ? change : {};
4729
+ const { enabled, autoRecord, calendarReminders } = change && typeof change === "object" ? change : {};
4379
4730
  if (typeof enabled === "boolean" && enabled !== this.options.store.enabled()) {
4380
4731
  this.options.store.setEnabled(enabled);
4381
4732
  this.options.log(`Meeting detection: turned ${enabled ? "on" : "off"}.`);
@@ -4389,6 +4740,12 @@ var MeetingDetection = class {
4389
4740
  );
4390
4741
  this.changed();
4391
4742
  }
4743
+ if (typeof calendarReminders === "boolean" && this.reminders && calendarReminders !== this.calendarRemindersOn() && this.options.store.setCalendarReminders) {
4744
+ this.options.store.setCalendarReminders(calendarReminders);
4745
+ this.options.log(`Meeting reminders: turned ${calendarReminders ? "on" : "off"}.`);
4746
+ this.apply();
4747
+ this.changed();
4748
+ }
4392
4749
  return this.status();
4393
4750
  }
4394
4751
  /** Runs `listener` when the switch or its problem changes. */
@@ -4439,7 +4796,10 @@ var MeetingDetection = class {
4439
4796
  canOpen: false
4440
4797
  });
4441
4798
  }
4442
- this.prompter.setRecording(this.recordingPages.size > 0, now);
4799
+ const any = this.recordingPages.size > 0;
4800
+ if (!any) this.recordingSince = null;
4801
+ else this.recordingSince ??= now;
4802
+ this.prompter.setRecording(any, now);
4443
4803
  for (const listener of this.recordingListeners) listener();
4444
4804
  }
4445
4805
  /** The meeting being recorded here, the newest when pages record several; null for none. */
@@ -4503,24 +4863,43 @@ var MeetingDetection = class {
4503
4863
  }
4504
4864
  this.prompter.observe([], this.now());
4505
4865
  }
4866
+ /** Stop the helper and the reminders, as the app quits. */
4867
+ shutdown() {
4868
+ this.stop();
4869
+ this.reminders?.stop();
4870
+ }
4506
4871
  present(prompt) {
4507
4872
  const app4 = prompt.app.id;
4508
4873
  this.options.log(`Meeting detection: ${PRESENTED[prompt.kind]} (${app4}).`);
4509
- let open = true;
4510
- const shown = this.options.view.show(prompt, (outcome) => {
4511
- if (!open) return;
4512
- open = false;
4874
+ return this.showCard(prompt, (outcome) => {
4513
4875
  this.prompter.dismissed(prompt);
4514
- this.options.log(`Meeting detection: ${OUTCOMES[outcome]} (${app4}).`);
4876
+ this.options.log(`Meeting detection: ${OUTCOMES2[outcome]} (${app4}).`);
4515
4877
  if (outcome === "chosen") {
4516
4878
  this.deliver(promptRequest(prompt), { quiet: prompt.kind === "recording" });
4517
4879
  }
4518
4880
  });
4881
+ }
4882
+ /**
4883
+ * One card at a time, for calls and reminders alike: a new question takes
4884
+ * the place of the one showing, which then counts as timed out.
4885
+ */
4886
+ showCard(prompt, done) {
4887
+ this.onCard?.replaced();
4888
+ let open = true;
4889
+ const finish = (outcome) => {
4890
+ if (!open) return;
4891
+ open = false;
4892
+ if (this.onCard?.prompt === prompt) this.onCard = null;
4893
+ done(outcome);
4894
+ };
4895
+ this.onCard = { prompt, replaced: () => finish("expired") };
4896
+ const shown = this.options.view.show(prompt, finish);
4519
4897
  return {
4520
4898
  close: () => {
4521
4899
  if (!open) return;
4522
4900
  open = false;
4523
- this.options.log(`Meeting detection: took the question back (${app4}).`);
4901
+ if (this.onCard?.prompt === prompt) this.onCard = null;
4902
+ this.options.log(`Meeting detection: took the question back (${prompt.app.id}).`);
4524
4903
  shown.close();
4525
4904
  }
4526
4905
  };
@@ -4559,6 +4938,13 @@ var MeetingDetection = class {
4559
4938
  page.send(contract_exports.DESKTOP_IPC.meetingDetectionRequest, request);
4560
4939
  return true;
4561
4940
  }
4941
+ /** Whether the page a choice would go to (the active account's) records. */
4942
+ targetRecords() {
4943
+ if (this.recordingPages.size === 0) return false;
4944
+ const pages = this.livePages();
4945
+ const page = this.options.chooseTarget ? this.options.chooseTarget(pages) : pages.at(-1);
4946
+ return page !== void 0 && this.recordingPages.has(page);
4947
+ }
4562
4948
  livePages() {
4563
4949
  for (let index = this.pages.length - 1; index >= 0; index -= 1) {
4564
4950
  if (this.pages[index].isDestroyed()) this.pages.splice(index, 1);
@@ -4603,7 +4989,18 @@ var MeetingDetection = class {
4603
4989
  autoRecord() {
4604
4990
  return this.options.store.autoRecord?.() === true;
4605
4991
  }
4992
+ calendarRemindersOn() {
4993
+ return this.options.store.calendarReminders?.() !== false;
4994
+ }
4995
+ /** Reminders run while they're on and a page here can record, whether or not calls are noticed. */
4996
+ remindersWanted() {
4997
+ return this.calendarRemindersOn() && this.options.store.canRecord();
4998
+ }
4606
4999
  apply() {
5000
+ if (this.reminders) {
5001
+ if (this.remindersWanted()) this.reminders.start();
5002
+ else this.reminders.stop();
5003
+ }
4607
5004
  const wanted = this.usable() && this.options.store.enabled() && this.options.store.canRecord();
4608
5005
  this.prompter.setEnabled(wanted, this.now());
4609
5006
  if (wanted && !this.running) {
@@ -4678,7 +5075,7 @@ var MeetingDetection = class {
4678
5075
  this.changed();
4679
5076
  }
4680
5077
  };
4681
- var OUTCOMES = {
5078
+ var OUTCOMES2 = {
4682
5079
  chosen: "the person chose it",
4683
5080
  dismissed: "the person closed the question",
4684
5081
  expired: "the question timed out"
@@ -4686,7 +5083,8 @@ var OUTCOMES = {
4686
5083
  var PRESENTED = {
4687
5084
  record: "asked to record a call",
4688
5085
  stop: "asked to stop recording",
4689
- recording: "said a call is being recorded"
5086
+ recording: "said a call is being recorded",
5087
+ join: "offered to join a calendar meeting"
4690
5088
  };
4691
5089
 
4692
5090
  // src/main/meeting-detection/card-page.ts
@@ -5004,10 +5402,13 @@ var MeetingPromptCard = class {
5004
5402
  const text = promptText(prompt, words);
5005
5403
  const state = {
5006
5404
  token,
5007
- title: words.title,
5405
+ title: prompt.kind === "join" ? words.reminderTitle ?? ENGLISH_MEETING_WORDS.reminderTitle : words.title,
5008
5406
  ...text,
5009
5407
  icon: this.options.icon?.() ?? null,
5010
- timeoutMs: prompt.kind === "stop" ? 0 : this.options.timeoutMs ?? MEETING_CARD_TIMEOUT_MS
5408
+ timeoutMs: prompt.kind === "stop" ? 0 : (
5409
+ // A reminder stays until a few minutes after its meeting started.
5410
+ prompt.kind === "join" ? prompt.reminder.timeoutMs : this.options.timeoutMs ?? MEETING_CARD_TIMEOUT_MS
5411
+ )
5011
5412
  };
5012
5413
  const measured = await pageAnswer(
5013
5414
  window.webContents.executeJavaScript(`render(${JSON.stringify(state)})`),
@@ -5077,6 +5478,7 @@ function createMeetingDetection(options) {
5077
5478
  }),
5078
5479
  reveal: options.reveal,
5079
5480
  ...options.chooseTarget ? { chooseTarget: options.chooseTarget } : {},
5481
+ ...options.calendar ? { calendar: options.calendar } : {},
5080
5482
  log
5081
5483
  });
5082
5484
  }
@@ -5768,13 +6170,13 @@ var AppTray = class {
5768
6170
  /** Drawn once and kept: a few small images. */
5769
6171
  image(glyph, frame) {
5770
6172
  const style = trayGlyphStyle(this.platform);
5771
- const key = `${glyph}/${frame}/${style.color.join(",")}`;
5772
- let image = this.images.get(key);
6173
+ const key2 = `${glyph}/${frame}/${style.color.join(",")}`;
6174
+ let image = this.images.get(key2);
5773
6175
  if (!image) {
5774
6176
  const { buffer, ...size } = trayGlyphBitmap(glyph, style, frame);
5775
6177
  image = nativeImage2.createFromBitmap(buffer, size);
5776
6178
  if (this.platform === "darwin") image.setTemplateImage(true);
5777
- this.images.set(key, image);
6179
+ this.images.set(key2, image);
5778
6180
  }
5779
6181
  return image;
5780
6182
  }
@@ -6939,6 +7341,33 @@ var DesktopShell = class _DesktopShell {
6939
7341
  const shown = accountId ? this.window?.contentsFor(accountId) : null;
6940
7342
  return pages.find((page) => page === shown);
6941
7343
  },
7344
+ // Reminders before the active account's calendar meetings; that account records.
7345
+ calendar: {
7346
+ account: () => {
7347
+ const active = this.store.active();
7348
+ return active && !active.signedOut && active.workspaceId ? { id: active.id } : null;
7349
+ },
7350
+ upcoming: async (accountId) => {
7351
+ const workspaceId = this.store.get(accountId)?.workspaceId;
7352
+ const client = workspaceId ? await this.client(accountId) : null;
7353
+ if (!client || !workspaceId) return null;
7354
+ try {
7355
+ return await client.requestJson(
7356
+ "GET",
7357
+ `/v1/workspaces/${encodeURIComponent(workspaceId)}/upcoming-meetings`,
7358
+ void 0,
7359
+ {},
7360
+ { timeoutMs: 15e3 }
7361
+ );
7362
+ } catch (caught) {
7363
+ if (caught.status === 404) return null;
7364
+ throw caught;
7365
+ }
7366
+ },
7367
+ openUrl: (url) => {
7368
+ if (new URL(url).protocol === "https:") void shell3.openExternal(url);
7369
+ }
7370
+ },
6942
7371
  log: (message, caught) => console.warn(message, caught ?? "")
6943
7372
  });
6944
7373
  this.appShots = new AppShots({
@@ -7116,7 +7545,12 @@ var DesktopShell = class _DesktopShell {
7116
7545
  setTimeout(() => migrateMacLoginItem(this.config.appId), 5e3);
7117
7546
  }
7118
7547
  app3.on("activate", () => this.reveal());
7119
- powerMonitor2.on("resume", () => this.retryUnreachable());
7548
+ powerMonitor2.on("resume", () => {
7549
+ this.retryUnreachable();
7550
+ this.meetings.refreshCalendar();
7551
+ });
7552
+ powerMonitor2.on("unlock-screen", () => this.meetings.refreshCalendar());
7553
+ app3.on("browser-window-focus", () => this.meetings.windowFocused());
7120
7554
  app3.on("before-quit", (event) => {
7121
7555
  if (this.quitConfirmed) {
7122
7556
  this.quitting = true;
@@ -7139,7 +7573,7 @@ var DesktopShell = class _DesktopShell {
7139
7573
  this.appShots.stop();
7140
7574
  this.systemAudio.stopAll();
7141
7575
  this.dictation.stop();
7142
- this.meetings.stop();
7576
+ this.meetings.shutdown();
7143
7577
  this.computer.shutdownNow();
7144
7578
  });
7145
7579
  app3.on("window-all-closed", () => {
@@ -7756,10 +8190,10 @@ var DesktopShell = class _DesktopShell {
7756
8190
  }
7757
8191
  const actions = readMenuActions(value);
7758
8192
  if (!actions) return;
7759
- const key = JSON.stringify(actions);
7760
- if ((this.pageMenuActions.get(account.id)?.key ?? "[]") === key) return;
8193
+ const key2 = JSON.stringify(actions);
8194
+ if ((this.pageMenuActions.get(account.id)?.key ?? "[]") === key2) return;
7761
8195
  if (actions.length === 0) this.pageMenuActions.delete(account.id);
7762
- else this.pageMenuActions.set(account.id, { actions, key });
8196
+ else this.pageMenuActions.set(account.id, { actions, key: key2 });
7763
8197
  if (this.store.snapshot().activeId === account.id) Menu4.setApplicationMenu(this.menu());
7764
8198
  });
7765
8199
  ipcMain.on(contract_exports.DESKTOP_IPC.appearanceSet, (event, appearance) => {
@@ -7891,6 +8325,7 @@ var DesktopShell = class _DesktopShell {
7891
8325
  else send();
7892
8326
  }
7893
8327
  accountsChanged() {
8328
+ this.meetings.accountChanged();
7894
8329
  this.broadcast(contract_exports.DESKTOP_IPC.accountsChanged, this.accountsSnapshot());
7895
8330
  Menu4.setApplicationMenu(this.menu());
7896
8331
  void this.refreshTray();
@@ -8059,17 +8494,17 @@ function cookieFromHeader(url, header) {
8059
8494
  };
8060
8495
  for (const attribute of attributes) {
8061
8496
  const [rawKey = "", ...rest] = attribute.split("=");
8062
- const key = rawKey.trim().toLowerCase();
8497
+ const key2 = rawKey.trim().toLowerCase();
8063
8498
  const value = rest.join("=").trim();
8064
- if (key === "path") details.path = value;
8065
- else if (key === "domain") details.domain = value;
8066
- else if (key === "secure") details.secure = true;
8067
- else if (key === "httponly") details.httpOnly = true;
8068
- else if (key === "max-age") details.expirationDate = Date.now() / 1e3 + Number(value);
8069
- else if (key === "expires" && details.expirationDate === void 0) {
8499
+ if (key2 === "path") details.path = value;
8500
+ else if (key2 === "domain") details.domain = value;
8501
+ else if (key2 === "secure") details.secure = true;
8502
+ else if (key2 === "httponly") details.httpOnly = true;
8503
+ else if (key2 === "max-age") details.expirationDate = Date.now() / 1e3 + Number(value);
8504
+ else if (key2 === "expires" && details.expirationDate === void 0) {
8070
8505
  const at = Date.parse(value);
8071
8506
  if (Number.isFinite(at)) details.expirationDate = at / 1e3;
8072
- } else if (key === "samesite") {
8507
+ } else if (key2 === "samesite") {
8073
8508
  const lower = value.toLowerCase();
8074
8509
  details.sameSite = lower === "strict" ? "strict" : lower === "none" ? "no_restriction" : "lax";
8075
8510
  }