From 1be0f74cfa54c5d4e08b448e743001d4968c89cc Mon Sep 17 00:00:00 2001 From: Pham Ngoc Duong Date: Sun, 5 Jan 2025 08:49:52 +0700 Subject: [PATCH] feat: actively invalidate cdn cache --- src/app.config.ts | 4 +- .../language-models.ts | 6 +++ src/entrypoints/background/listeners.ts | 8 ++++ src/entrypoints/content-scripts/index.ts | 4 ++ .../cs-ui-plugins-loader/setup-root.tsx | 12 +++++ .../content-scripts/loaders/index.ts | 2 +- .../content-scripts/loading-indicator.ts | 45 +++++++++++++++++++ src/services/cplx-api/cplx-api.ts | 28 ++++++++++-- src/services/cs-loader-registry.ts | 1 + .../extension-local-storage.types.ts | 1 + .../storage-defaults.ts | 1 + 11 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 src/entrypoints/content-scripts/loading-indicator.ts diff --git a/src/app.config.ts b/src/app.config.ts index f85204d4..1c66b295 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -9,7 +9,7 @@ const EnvVarsSchema = z.object({ .enum(["chrome", "firefox"]) .optional() .default("chrome"), - VITE_CPLX_API_URL: z.string(), + VITE_CPLX_CDN_URL: z.string(), DEV: z.string().or(z.boolean()).optional(), }); @@ -19,7 +19,7 @@ const APP_CONFIG = { VERSION: packageJson.version, BROWSER: parsedEnv.VITE_TARGET_BROWSER, IS_DEV: Boolean(parsedEnv.DEV) || parsedEnv.NODE_ENV === "development", - CPLX_API_URL: parsedEnv.VITE_CPLX_API_URL, + CPLX_CDN_URL: parsedEnv.VITE_CPLX_CDN_URL, "perplexity-ai": { globalMatches: ["https://www.perplexity.ai/*", "https://perplexity.ai/*"], globalExcludeMatches: [ diff --git a/src/data/plugins/query-box/language-model-selector/language-models.ts b/src/data/plugins/query-box/language-model-selector/language-models.ts index 46f99929..0e04a903 100644 --- a/src/data/plugins/query-box/language-model-selector/language-models.ts +++ b/src/data/plugins/query-box/language-model-selector/language-models.ts @@ -21,6 +21,12 @@ export const localLanguageModels = [ code: "claude35haiku", provider: "Anthropic", }, + { + label: "O1", + shortLabel: "O1", + code: "o1", + provider: "OpenAI", + }, { label: "GPT-4 Omni", shortLabel: "GPT-4o", diff --git a/src/entrypoints/background/listeners.ts b/src/entrypoints/background/listeners.ts index 7eb6d3dc..11c836d7 100644 --- a/src/entrypoints/background/listeners.ts +++ b/src/entrypoints/background/listeners.ts @@ -20,6 +20,14 @@ export function setupBackgroundListeners() { else chrome.runtime.openOptionsPage(); }); + chrome.runtime.onInstalled.addListener(({ reason }) => { + if (reason !== chrome.runtime.OnInstalledReason.UPDATE) return; + + ExtensionLocalStorageService.set((draft) => { + draft.cdnLastUpdated = Date.now(); + }); + }); + chrome.runtime.onInstalled.addListener(({ reason, previousVersion }) => { if (reason === chrome.runtime.OnInstalledReason.INSTALL) { chrome.tabs.create({ diff --git a/src/entrypoints/content-scripts/index.ts b/src/entrypoints/content-scripts/index.ts index d6f6e665..6a55d92c 100644 --- a/src/entrypoints/content-scripts/index.ts +++ b/src/entrypoints/content-scripts/index.ts @@ -1,9 +1,13 @@ import "@/utils/jquery.extensions"; +import { showInitializingIndicator } from "@/entrypoints/content-scripts/loading-indicator"; import { CsLoaderRegistry } from "@/services/cs-loader-registry"; import { contentScriptGuard } from "@/utils/content-scripts-guard"; + import "@/entrypoints/content-scripts/loaders"; +$(showInitializingIndicator); + contentScriptGuard(); CsLoaderRegistry.executeAll(); diff --git a/src/entrypoints/content-scripts/loaders/cs-ui-plugins-loader/setup-root.tsx b/src/entrypoints/content-scripts/loaders/cs-ui-plugins-loader/setup-root.tsx index f000906c..6879994e 100644 --- a/src/entrypoints/content-scripts/loaders/cs-ui-plugins-loader/setup-root.tsx +++ b/src/entrypoints/content-scripts/loaders/cs-ui-plugins-loader/setup-root.tsx @@ -25,6 +25,18 @@ CsLoaderRegistry.register({ const root = createRoot($root[0]); const router = createRouter(); + setTimeout(() => { + $("#cplx-initializing-indicator div") + .removeClass("tw-animate-in tw-fade-in") + .addClass("tw-animate-out tw-fade-out tw-duration-1000"); + + $("#cplx-initializing-indicator-style").remove(); + + setTimeout(() => { + $("#cplx-initializing-indicator").remove(); + }, 200); + }, 500); + root.render( diff --git a/src/entrypoints/content-scripts/loaders/index.ts b/src/entrypoints/content-scripts/loaders/index.ts index 97b6e11b..87276415 100644 --- a/src/entrypoints/content-scripts/loaders/index.ts +++ b/src/entrypoints/content-scripts/loaders/index.ts @@ -42,7 +42,7 @@ import "@/features/plugins/hide-get-mobile-app-cta-btn/hide-get-mobile-app-cta-b import "@/features/plugins/zen-mode/zen-mode"; import "@/features/plugins/block-analytic-events/network-intercept-middlewares"; -// Global Store +// Global Stores import "@/data/color-scheme-store"; // Loaders diff --git a/src/entrypoints/content-scripts/loading-indicator.ts b/src/entrypoints/content-scripts/loading-indicator.ts new file mode 100644 index 00000000..5e8173f4 --- /dev/null +++ b/src/entrypoints/content-scripts/loading-indicator.ts @@ -0,0 +1,45 @@ +import csUiRootCss from "@/assets/cs.css?inline"; +import { getCookie } from "@/utils/utils"; + +export function showInitializingIndicator() { + const rawColorScheme = getCookie("colorScheme"); + const colorScheme = + rawColorScheme === "light" || rawColorScheme === "dark" + ? rawColorScheme + : null; + + if (colorScheme === null) { + const preferredColorScheme = window.matchMedia( + "(prefers-color-scheme: dark)", + ).matches + ? "dark" + : "light"; + + $("html").attr("data-color-scheme", preferredColorScheme); + } else { + $("html").attr("data-color-scheme", colorScheme); + } + + const $tempStyle = $("