Skip to content

Commit

Permalink
Fix/latex auto on bug (#8)
Browse files Browse the repository at this point in the history
* Feat: add latex check

Chore: improve makeExcluder, add textarea to globally excluded elements

* Update: delay auto on when latex is present

* Update: declare autoOnDelay on default prefs

* Update: rewrite saved prefs when app is installed or updated

* Chore: simplify and type code

* Chore: improve index.d.ts

* Chore: update types

* Chore: fix typo
  • Loading branch information
asieduernest12 authored Aug 14, 2023
1 parent 25bd4b2 commit 0c54540
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 189 deletions.
50 changes: 16 additions & 34 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,39 @@
interface Prefs {
onPageLoad: boolean;
scope: string; //"global" | "local"
lineHeight: number;
edgeOpacity: number;
saccadesColor: string;
saccadesStyle: string;
saccadesInterval: number;
fixationStrength: number;
fixationEdgeOpacity: number;
MAX_FIXATION_PARTS: number;
FIXATION_LOWER_BOUND: number;
BR_WORD_STEM_PERCENTAGE: number;
}
import type defaultPrefs from '~services/preferences';

type Prefs = typeof defaultPrefs;
type PrefRecords = Record<string, Pref>;

interface PrefStore {
global: Prefs;
local: PrefRecords;
global: Prefs;
local: PrefRecords;
}

interface TabSession {
brMode: boolean;
origin?: string;
tabID?;
brMode: boolean;
origin?: string;
tabID?;
}

type TabSessionStore = Record<string, TabSession>;

type UpdateCallback = (tabSessions: PrefRecords) => PrefRecords;

type SetPrefsExternal = (
getOrigin: () => Promise<string>,
scope: string,
newPrefs: Prefs,
deleteOldLocal?: boolean,
) => Promise<void>;
type SetPrefsExternal = (getOrigin: () => Promise<string>, scope: string, newPrefs: Prefs, deleteOldLocal?: boolean) => Promise<void>;

type removeTabSession = (getTab: () => Promise<chrome.tabs.Tab>) => Promise<void>;


interface AppConfigPref {
displayColorMode: DisplayColorMode;
displayColorMode: DisplayColorMode;
}

declare namespace NodeJS {
interface ProcessEnv {
DEBUG: string;
TARGET: string;
SHORTCUT: string;
VERSION: string;
NAME: string;
}
interface ProcessEnv {
DEBUG: string;
TARGET: string;
SHORTCUT: string;
VERSION: string;
NAME: string;
}
}

declare module '*.scss';
17 changes: 10 additions & 7 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Storage } from '@plasmohq/storage';
import type { PrefStore } from 'index';

import Logger from '~services/Logger';
import TabHelper from '~services/TabHelper';
Expand Down Expand Up @@ -33,15 +34,17 @@ const fireUpdateNotification = async (eventReason: chrome.runtime.OnInstalledRea

const initializeUserPrefStorage = async () => {
try {
const prefStore = await storage.get(USER_PREF_STORE_KEY);
const prefStore: PrefStore = (await storage.get(USER_PREF_STORE_KEY)) ?? ({ global: {}, local: {} } as PrefStore);
Logger.logInfo('background: prefStore install value', prefStore);

if (!prefStore) {
await storage.set(USER_PREF_STORE_KEY, { global: defaultPrefs, local: {} });
Logger.logInfo('background: prefStore initialization processed', await storage.get(USER_PREF_STORE_KEY));
} else {
Logger.logInfo('background: prefStore initialization skipped', prefStore);
}
const newPrefs = {
global: { ...defaultPrefs, ...prefStore?.global },
local: { ...prefStore?.local },
};

Logger.logInfo('initializeUserPrefStorage', { newPrefs });

await storage.set(USER_PREF_STORE_KEY, newPrefs);
} catch (error) {
Logger.logError(error);
} finally {
Expand Down
Loading

0 comments on commit 0c54540

Please sign in to comment.