Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(chrome-ext): don't override with activation from WordPress page (#2103)

Elijah Potter433f197d5f00
diff --git a/packages/chrome-plugin/src/ProtocolClient.ts b/packages/chrome-plugin/src/ProtocolClient.ts
index d012aba5f..9027a2449 100644
--- a/packages/chrome-plugin/src/ProtocolClient.ts
+++ b/packages/chrome-plugin/src/ProtocolClient.ts
@@ -51,8 +51,16 @@ export default class ProtocolClient {
return (await chrome.runtime.sendMessage({ kind: 'getDomainStatus', domain })).enabled;
}
- public static async setDomainEnabled(domain: string, enabled: boolean): Promise<void> {
- await chrome.runtime.sendMessage({ kind: 'setDomainStatus', enabled, domain });
+ /** Set whether Harper is enabled for a given domain.
+ *
+ * @param overrideValue dictates whether this should override a previous setting.
+ * */
+ public static async setDomainEnabled(
+ domain: string,
+ enabled: boolean,
+ overrideValue = true,
+ ): Promise<void> {
+ await chrome.runtime.sendMessage({ kind: 'setDomainStatus', enabled, domain, overrideValue });
}
public static async getDefaultEnabled(): Promise<boolean> {
diff --git a/packages/chrome-plugin/src/background/index.ts b/packages/chrome-plugin/src/background/index.ts
index ec0213a99..058588d09 100644
--- a/packages/chrome-plugin/src/background/index.ts
+++ b/packages/chrome-plugin/src/background/index.ts
@@ -5,7 +5,6 @@ import {
ActivationKey,
type AddToUserDictionaryRequest,
createUnitResponse,
- type GetActivationKeyRequest,
type GetActivationKeyResponse,
type GetConfigRequest,
type GetConfigResponse,
@@ -228,7 +227,7 @@ async function handleGetDomainStatus(
}
async function handleSetDomainStatus(req: SetDomainStatusRequest): Promise<UnitResponse> {
- await setDomainEnable(req.domain, req.enabled);
+ await setDomainEnable(req.domain, req.enabled, req.overrideValue);
return createUnitResponse();
}
@@ -388,16 +387,27 @@ function formatDomainKey(domain: string): string {
}
/** Check if Harper has been enabled for a given domain. */
-async function enabledForDomain(domain: string): Promise<boolean> {
+async function enabledForDomain(domain: string): Promise<boolean | null> {
const req = await chrome.storage.local.get({
[formatDomainKey(domain)]: await enabledByDefault(),
});
return req[formatDomainKey(domain)];
}
-/** Set whether Harper is enabled for a given domain. */
-async function setDomainEnable(domain: string, status: boolean) {
- await chrome.storage.local.set({ [formatDomainKey(domain)]: status });
+/** Set whether Harper is enabled for a given domain.
+ *
+ * @param overrideValue dictates whether this should override a previous setting.
+ * */
+async function setDomainEnable(domain: string, status: boolean, overrideValue = true) {
+ let shouldSet = !(await isDomainSet(domain));
+
+ if (overrideValue) {
+ shouldSet = true;
+ }
+
+ if (shouldSet) {
+ await chrome.storage.local.set({ [formatDomainKey(domain)]: status });
+ }
}
/** Set whether Harper is enabled by default. */
diff --git a/packages/chrome-plugin/src/contentScript/index.ts b/packages/chrome-plugin/src/contentScript/index.ts
index 123475f08..cfc5b2d6c 100644
--- a/packages/chrome-plugin/src/contentScript/index.ts
+++ b/packages/chrome-plugin/src/contentScript/index.ts
@@ -4,7 +4,7 @@ import isWordPress from '../isWordPress';
import ProtocolClient from '../ProtocolClient';
if (isWordPress()) {
- ProtocolClient.setDomainEnabled(window.location.hostname, true);
+ ProtocolClient.setDomainEnabled(window.location.hostname, true, false);
}
const fw = new LintFramework((text, domain) => ProtocolClient.lint(text, domain), {
diff --git a/packages/chrome-plugin/src/protocol.ts b/packages/chrome-plugin/src/protocol.ts
index dc0540e3c..2005646c1 100644
--- a/packages/chrome-plugin/src/protocol.ts
+++ b/packages/chrome-plugin/src/protocol.ts
@@ -117,6 +117,8 @@ export type SetDomainStatusRequest = {
kind: 'setDomainStatus';
domain: string;
enabled: boolean;
+ /** Dictates whether this should override a previous setting. */
+ overrideValue: boolean;
};
export type SetDefaultStatusRequest = {