Skip to content
Closed
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
8 changes: 6 additions & 2 deletions src/helpers/sttConfigPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// awaited fetch stalls on auth resolution for seconds and then changes
// nothing (#1673).
export function needsSttConfigBeforeStart(settings) {
const s = settings || {};
const s = settings && typeof settings === "object" ? settings : {};
if (s.useLocalWhisper) return false;
if (s.cloudTranscriptionMode !== "openwhispr") return false;
const cloudMode =
typeof s.cloudTranscriptionMode === "string"
? s.cloudTranscriptionMode.trim().toLowerCase()
: "";
if (cloudMode !== "openwhispr") return false;
return !!s.isSignedIn;
}
15 changes: 15 additions & 0 deletions test/helpers/sttConfigPolicy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ describe("needsSttConfigBeforeStart", () => {
test("missing settings fail open to a non-blocking start", async () => {
const { needsSttConfigBeforeStart } = await loadPolicy();
assert.equal(needsSttConfigBeforeStart(null), false);
assert.equal(needsSttConfigBeforeStart(undefined), false);
assert.equal(needsSttConfigBeforeStart(123), false);
assert.equal(needsSttConfigBeforeStart(""), false);
assert.equal(needsSttConfigBeforeStart({}), false);
});

test("normalizes mixed-case and whitespace in cloudTranscriptionMode", async () => {
const { needsSttConfigBeforeStart } = await loadPolicy();
assert.equal(
needsSttConfigBeforeStart({
useLocalWhisper: false,
cloudTranscriptionMode: " OpenWhispr ",
isSignedIn: true,
}),
true
);
});
});
Loading