From f4e5256bb9c0a6d6a54cc5d2c759a32f756d8d38 Mon Sep 17 00:00:00 2001 From: linuxdev Date: Fri, 27 Dec 2024 22:10:47 -0500 Subject: [PATCH 01/10] fix: reddi disappearing text #288 --- src/services/siteOverrides.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/siteOverrides.ts b/src/services/siteOverrides.ts index 20aa612..5e0efd5 100644 --- a/src/services/siteOverrides.ts +++ b/src/services/siteOverrides.ts @@ -6,6 +6,7 @@ import Logger from '~services/Logger'; const siteOverrides = { 'play.google.com': `[br-mode=on] reader-rendered-page { overflow: auto !important; }`, + 'reddit.com': 'br-span, br-bold, br-fixation, br-edge { visibility : visible !important; }', }; /** From 7d966ae6adbbaf9ba1b80bc7d7b79e5e9fa132d0 Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 04:47:47 -0500 Subject: [PATCH 02/10] chore: remove bumb.txt --- bump.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 bump.txt diff --git a/bump.txt b/bump.txt deleted file mode 100644 index 18efdb9..0000000 --- a/bump.txt +++ /dev/null @@ -1 +0,0 @@ -1.1.8 From ab618c52fa60c323a0d1cd3d1bd44c8912079d6a Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 04:49:43 -0500 Subject: [PATCH 03/10] update/makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b261f6e..a4fa916 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL := /bin/bash .SILENT: -.PHONY: build +.PHONY: print-manifests build help: @@ -9,7 +9,7 @@ help: | sed -e 's/\[32m #-- /[33m/' print-manifests: ## print out build target manifests - @ls ./build/jiffyReader-* -t |grep -E '.(xpi|zip|crx)' | xargs -I {} sh -c 'unzip -p "{}" manifest.json | jq -r ". | \"Version: \(.version), Name: \(.name), Version Name: \(.version_name), Target: \(.target), Scope: \(.scope) {}\""' + @ls ./build/jiffyReader-* -t |grep -E '.(xpi|zip|crx)' | xargs -I {} sh -c 'unzip -p "{}" manifest.json | jq -r ". | \"Version: \(.version), Name: \(.name), Version Name: \(.version_name), Target: \(.target), Tag: \(.tag) {}\""' test-build-manifests: ## test build manifests @if make -s print-manifests | grep -E '(\W-\W|null)'; then exit 1; fi From 24ee65db5c658b5afda8a9e2ec557123cbaa01ed Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 04:51:07 -0500 Subject: [PATCH 04/10] update: packjson scripts and variable refs, add zod --- package.json | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 0d95ef9..62840a3 100644 --- a/package.json +++ b/package.json @@ -5,28 +5,28 @@ "description": "jiffy reader", "packageManager": "yarn@1.22.19", "scripts": { - "dev": "VERSION=\"$(npm pkg get version | tr -d '\"')\" TARGET=${TARGET:-chrome} NAME=${NAME:-\"jiffy-reader-chrome\"} TAG=${TAG:=local} VERSION_NAME=$VERSION-$TARGET-$TAG DEBUG=${DEBUG:-TRUE} SHORTCUT=${SHORTCUT:-\"Alt+B\"} plasmo dev --target=${MANIFEST_VERSION:-chrome-mv3}", - "buildx": "VERSION=\"$(npm pkg get version | tr -d '\"')\" TARGET=${TARGET:-chrome} NAME=${NAME:-\"Jiffy Reader\"} TAG=${TAG:=prod} VERSION_NAME=$VERSION-$TARGET-$TAG DEBUG=${DEBUG:-FALSE} SHORTCUT=${SHORTCUT:-\"Alt+B\"} plasmo build --target=${MANIFEST_VERSION:-chrome-mv3}", + "dev": "PLASMO_VERSION=\"$(npm pkg get version | tr -d '\"')\" PLASMO_TARGET=${PLASMO_TARGET:-chrome} PLASMO_NAME=${PLASMO_NAME:-\"jiffy-reader-chrome\"} PLASMO_TAG=${PLASMO_TAG:-dev} PLASMO_VERSION_NAME=$PLASMO_VERSION-$PLASMO_TARGET-$PLASMO_TAG PLASMO_DEBUG=${PLASMO_DEBUG:-TRUE} PLASMO_SHORTCUT=${PLASMO_SHORTCUT:-\"Alt+B\"} plasmo dev --target=${PLASMO_MANIFEST_VERSION:-chrome-mv3}", + "buildx": "PLASMO_VERSION=\"$(npm pkg get version | tr -d '\"')\" PLASMO_TARGET=${PLASMO_TARGET:-chrome} PLASMO_NAME=${PLASMO_NAME:-\"Jiffy Reader\"} PLASMO_TAG=${PLASMO_TAG:-prod} PLASMO_VERSION_NAME=$PLASMO_VERSION-$PLASMO_TARGET-$PLASMO_TAG PLASMO_DEBUG=${PLASMO_DEBUG:-FALSE} PLASMO_SHORTCUT=${PLASMO_SHORTCUT:-\"Alt+B\"} plasmo build --target=${PLASMO_MANIFEST_VERSION:-chrome-mv3}", "build": "npm run build:opera && npm run build:chrome & npm run build:firefox & npm run build:safari", "dev:chrome": "npm run dev", - "dev:firefox": "NAME=jiffy-reader-firefox TARGET=firefox SHORTCUT=\"Alt+W\" MANIFEST_VERSION=firefox-mv2 npm run dev", - "dev:safari": "NAME=jiffy-reader-safari TARGET=safari SHORTCUT=\"Alt+W\" MANIFEST_VERSION=safari-mv2 npm run dev", + "dev:firefox": "PLASMO_NAME=jiffy-reader-firefox PLASMO_TARGET=firefox PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=firefox-mv2 npm run dev", + "dev:safari": "PLASMO_NAME=jiffy-reader-safari PLASMO_TARGET=safari PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=safari-mv2 npm run dev", "build:chrome": "npm run buildx && npm run bundle:chrome", - "build:opera": "TARGET=opera npm run build:chrome && npm run bundle:opera", - "build:firefox": "NAME=jiffy-reader-firefox TARGET=firefox SHORTCUT=\"Alt+W\" MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox", - "build:safari": "NAME=jiffy-reader-safari TARGET=safari SHORTCUT=\"Alt+W\" MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari", - "gh:build:chrome": "TARGET=chrome SHORTCUT=\"Alt+B\" MANIFEST_VERSION=chrome-mv3 npm run buildx && npm run bundle:chrome", - "gh:build:opera": "TARGET=opera SHORTCUT=\"Alt+B\" MANIFEST_VERSION=chrome-mv3 npm run buildx && npm run bundle:opera", - "gh:build:firefox": "TARGET=firefox SHORTCUT=\"Alt+W\" MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox", - "gh:build:safari": "TARGET=safari SHORTCUT=\"Alt+W\" MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari", - "gh:build": "echo 'TAG=prod NODE_ENV=production npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'", - "gh:build:development": "echo 'TAG=dev NODE_ENV=development NAME=Jiffy-Reader-Dev npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'", - "gh:build:bookmarklet": "VERSION=\"$(npm pkg get version | tr -d '\"')\" node src/Bookmarklet/esbuild.mjs", + "build:opera": "PLASMO_TARGET=opera PLASMO_MANIFEST_VERSION=opera-mv3 npm run build:chrome && npm run bundle:opera", + "build:firefox": "PLASMO_NAME=jiffy-reader-firefox PLASMO_TARGET=firefox PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox", + "build:safari": "PLASMO_NAME=jiffy-reader-safari PLASMO_TARGET=safari PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari", + "gh:build:chrome": "PLASMO_TARGET=chrome PLASMO_SHORTCUT=\"Alt+B\" npm run buildx && npm run bundle:chrome", + "gh:build:opera": "PLASMO_TARGET=opera PLASMO_SHORTCUT=\"Alt+B\" PLASMO_MANIFEST_VERSION=opera-mv3 npm run buildx && npm run bundle:opera", + "gh:build:firefox": "PLASMO_TARGET=firefox PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=firefox-mv2 npm run buildx && npm run bundle:firefox", + "gh:build:safari": "PLASMO_TARGET=safari PLASMO_SHORTCUT=\"Alt+W\" PLASMO_MANIFEST_VERSION=safari-mv2 npm run buildx && npm run bundle:safari", + "gh:build": "echo 'PLASMO_TAG=prod NODE_ENV=production npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'", + "gh:build:development": "echo 'PLASMO_TAG=dev NODE_ENV=development PLASMO_NAME=Jiffy-Reader-Dev npm run gh:build:' | xargs -I{} bash -c '{}opera && {}chrome & {}firefox & {}safari & wait'", + "gh:build:bookmarklet": "PLASMO_VERSION=\"$(npm pkg get version | tr -d '\"')\" node src/Bookmarklet/esbuild.mjs", "bundle": "npm run bundle:chrome & npm run bundle:firefix & npm run bundle:safari", - "bundle:firefox": "cd build/firefox-mv2-prod/ && zip -r ../jiffyReader-firefox-$TAG.xpi ./*", - "bundle:safari": "cd build/safari-mv2-prod/ && zip -r ../jiffyReader-safari-$TAG.xpi ./*", - "bundle:chrome": "cd build/chrome-mv3-prod && zip -r ../jiffyReader-chrome-$TAG.zip ./*", - "bundle:opera": "rm -rf build/opera-mv3-prod; cp -r build/chrome-mv3-prod build/opera-mv3-prod && cd build/opera-mv3-prod && zip -r ../jiffyReader-opera-$TAG.crx ./*", + "bundle:firefox": "cd build/firefox-mv2-$PLASMO_TAG/ && zip -r ../jiffyReader-firefox-$PLASMO_TAG.xpi ./*", + "bundle:safari": "cd build/safari-mv2-$PLASMO_TAG/ && zip -r ../jiffyReader-safari-$PLASMO_TAG.xpi ./*", + "bundle:chrome": "cd build/chrome-mv3-$PLASMO_TAG && zip -r ../jiffyReader-chrome-$PLASMO_TAG.zip ./*", + "bundle:opera": "cd build/opera-mv3-$PLASMO_TAG && zip -r ../jiffyReader-opera-$PLASMO_TAG.crx ./*", "build:ios": "xcrun safari-web-extension-converter --rebuild-project \"Jiffy reader/Jiffy reader.xcodeproj\"", "build:xcode": "pnpm build:safari && xcrun safari-web-extension-converter --swift --no-open --force --bundle-identifier com.jiffyreader build/safari-mv2-prod", "build:xcode:all": "pnpm build:xcode && pnpm build:ios", @@ -48,7 +48,8 @@ "postcss": "^8.4.49", "react": "18.2.0", "react-dom": "18.2.0", - "webpack": "^4.47.0" + "webpack": "^4.47.0", + "zod": "^3.24.1" }, "devDependencies": { "@parcel/transformer-sass": "2.6.2", @@ -72,13 +73,12 @@ "typescript": "4.7.4" }, "manifest": { - "name": "$NAME", - "target": "$TARGET", - "version": "$VERSION", - "tag": "$TAG", - "version_name": "$VERSION_NAME", + "name": "$PLASMO_NAME", + "target": "$PLASMO_TARGET", + "version": "$PLASMO_VERSION", + "tag": "$PLASMO_TAG", + "version_name": "$PLASMO_VERSION_NAME", "environment": "$NODE_ENV", - "scope": "$TAG", "description": "A Browser Extension for Faster Reading on ANY website!", "default_locale": "en", "permissions": [ @@ -92,7 +92,7 @@ "commands": { "toggle-bionic": { "suggested_key": { - "default": "$SHORTCUT" + "default": "$PLASMO_SHORTCUT" }, "description": "Toggle bionic reading mode" } From 1b37f46b376c33d55ca1fe1f61739f9fd2fe3f17 Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 04:54:18 -0500 Subject: [PATCH 05/10] update/packj: add test script and update pnpm-lockfile --- package.json | 5 +++-- pnpm-lock.yaml | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 62840a3..c585125 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,9 @@ "build:xcode:all": "pnpm build:xcode && pnpm build:ios", "dev:xcode": "xcrun safari-web-extension-converter --swift --no-open --force --bundle-identifier com.jiffyreader build/safari-mv2-dev", "release": "if [ 0 -eq $(git log --oneline | head -n1 | grep 'chore(release)' | wc -l) ]; then commit-and-tag-version; fi", - "lint": "prettier -w src/ ; eslint --fix src/", - "test": "make -s build;# test is unstable';" + "lint": "eslint src/", + "lint:fix": "eslint --fix src/", + "test": "make -s build print-manifests; # test is unstable';" }, "dependencies": { "@plasmohq/prettier-plugin-sort-imports": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 074e0bc..ace5e05 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ dependencies: webpack: specifier: ^4.47.0 version: 4.47.0 + zod: + specifier: ^3.24.1 + version: 3.24.1 devDependencies: '@parcel/transformer-sass': @@ -12198,3 +12201,7 @@ packages: compress-commons: 4.1.2 readable-stream: 3.6.2 dev: false + + /zod@3.24.1: + resolution: {integrity: sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==} + dev: false From e5d136df3e61f2cf979ec1611d9fd522d458837f Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 05:05:42 -0500 Subject: [PATCH 06/10] refactor: env references to envService --- src/Bookmarklet/esbuild.mjs | 2 +- src/background/index.ts | 9 ++-- src/contents/content.tsx | 7 +-- src/popup/context.tsx | 3 +- src/popup/index.tsx | 6 +-- src/popup/indexNew.tsx | 9 ++-- src/popup/indexOld.tsx | 10 ++-- src/services/Logger.ts | 12 ++--- src/services/TrackEventService.ts | 7 +-- src/services/config.ts | 3 +- src/services/envService.ts | 81 +++++++++++++++++++++++++++++++ src/services/usePrefs.tsx | 4 +- 12 files changed, 121 insertions(+), 32 deletions(-) create mode 100644 src/services/envService.ts diff --git a/src/Bookmarklet/esbuild.mjs b/src/Bookmarklet/esbuild.mjs index 874e740..84f8168 100644 --- a/src/Bookmarklet/esbuild.mjs +++ b/src/Bookmarklet/esbuild.mjs @@ -7,7 +7,7 @@ const /** @type {import('esbuild').BuildOptions} */ defaultConfigs = { minify: true, write: false, plugins: [sassPlugin({ type: 'css-text' })], - define: { 'process.env.DEBUG': '"false"' }, + define: { 'envService.DEBUG': '"false"' }, tsconfig: './tsconfig.json', }; diff --git a/src/background/index.ts b/src/background/index.ts index 88d53c6..b3d89d7 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -4,6 +4,7 @@ import M from 'mellowtel'; import { CONFIG_KEY, DISABLE_LOGS } from '~constants'; import { APP_PREFS_STORE_KEY, DisplayColorMode, STORAGE_AREA, USER_PREF_STORE_KEY } from '~services/config'; +import { envService } from '~services/envService'; import Logger from '~services/Logger'; import defaultPrefs from '~services/preferences'; import runTimeHandler from '~services/runTimeHandler'; @@ -33,14 +34,14 @@ const setBadgeText = (badgeTextDetails: chrome.action.BadgeTextDetails, runner = return chrome?.action?.setBadgeText(badgeTextDetails) || browser.browserAction.setBadgeText(badgeTextDetails); }; -const openInstallationWelcomePage = async (eventReason: chrome.runtime.OnInstalledReason, browserTargetName: string = process.env.PLASMO_TARGET) => { +const openInstallationWelcomePage = async (eventReason: chrome.runtime.OnInstalledReason, browserTargetName: string = envService.PLASMO_TARGET) => { // if (await storage.get(USER_PREF_STORE_KEY)) { // return; // } chrome.tabs.create({ active: true, - url: `https://jiffyreader.com/welcome?browser=${browserTargetName}&event=${eventReason}&version=${process.env.VERSION}`, + url: `https://jiffyreader.com/welcome?browser=${browserTargetName}&event=${eventReason}&version=${envService.VERSION}`, }); }; @@ -148,7 +149,7 @@ async function onInstallHandler(event: chrome.runtime.InstalledDetails) { const eventReason = event.reason; - const newVersion = process.env.VERSION; + const newVersion = envService.VERSION; const { previousVersion } = event; const isNewVersion = previousVersion !== newVersion; Logger.logInfo({ newVersion, previousVersion, isNewVersion }); @@ -161,7 +162,7 @@ async function onInstallHandler(event: chrome.runtime.InstalledDetails) { previousVersion, }); - if (isNewVersion && /install/i.test(eventReason) && process.env.NODE_ENV === 'production') { + if (isNewVersion && /install/i.test(eventReason) && envService.NODE_ENV === 'production') { openInstallationWelcomePage(eventReason); } diff --git a/src/contents/content.tsx b/src/contents/content.tsx index b6c0a15..cf41850 100644 --- a/src/contents/content.tsx +++ b/src/contents/content.tsx @@ -5,6 +5,7 @@ import type { PlasmoContentScript } from 'plasmo'; import { useEffect, useState } from 'react'; import documentParser from '~services/documentParser'; +import { envService } from '~services/envService'; import Logger from '~services/Logger'; import overrides from '~services/siteOverrides'; import usePrefs from '~services/usePrefs'; @@ -160,13 +161,13 @@ const IndexContent = () => { const getCollapseExpandBtn = () => ; - const showDebugOverLay = (show) => { - if (!show) return; + const showDebugOverLay = (show = !envService.isProduction) => { + if (show) return; return (
- Target {process.env.PLASMO_TARGET} + Target {envService.PLASMO_TARGET} {getCollapseExpandBtn()}
diff --git a/src/popup/context.tsx b/src/popup/context.tsx index 631a6c4..ccaf997 100644 --- a/src/popup/context.tsx +++ b/src/popup/context.tsx @@ -1,5 +1,6 @@ import { Storage } from '@plasmohq/storage'; import { createContext, useContext, useEffect, useReducer } from 'react'; +import { envService } from '~services/envService'; let storage = { key: 'context.store', @@ -13,7 +14,7 @@ let storage = { }; const rawValues = { - isDebugDataVisible: !/production/i.test(process.env.NODE_ENV), + isDebugDataVisible: envService.showDebugInfo, }; const initialPopupContextValue = { diff --git a/src/popup/index.tsx b/src/popup/index.tsx index c289a67..a141f51 100644 --- a/src/popup/index.tsx +++ b/src/popup/index.tsx @@ -15,12 +15,13 @@ import documentParser from '~services/documentParser'; import runTimeHandler from '~services/runTimeHandler'; import TrackEventService, { EventCategory } from '~services/TrackEventService'; +import { envService } from '~services/envService'; import PopupContextProvider from './context'; import IndexPopupNew from './indexNew'; import IndexPopupOld from './indexOld'; import { useShowDebugSwitch } from './shorcut'; -const badCapScroll = /safari/i.test(process.env.PLASMO_TARGET) ? { overflowY: 'scroll', height: '600px' } : {}; +const badCapScroll = /safari/i.test(envService.PLASMO_TARGET) ? { overflowY: 'scroll', height: '600px' } : {}; const DisplayVersion = ({ displayVersion }) => { if (displayVersion === 'old') return ; @@ -40,11 +41,10 @@ const FIRST_FOOTER_MESSAGE_INDEX = 1; function IndexPopup() { const [activeTab, setActiveTab] = useState(null as chrome.tabs.Tab); const [footerMessageIndex, setFooterMeessageIndex] = useState(null); - const [isDebugDataVisible, setIsDebugDataVisible] = useShowDebugSwitch(); const getTabOriginfn = useCallback(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), [TabHelper]); - const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, process.env.PLASMO_TARGET); + const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, envService.PLASMO_TARGET); const [tabSession, setTabSession] = useState(null); diff --git a/src/popup/indexNew.tsx b/src/popup/indexNew.tsx index ed6b450..c0479bf 100644 --- a/src/popup/indexNew.tsx +++ b/src/popup/indexNew.tsx @@ -16,6 +16,7 @@ import documentParser from '~services/documentParser'; import defaultPrefs from '~services/preferences'; import runTimeHandler from '~services/runTimeHandler'; +import { envService } from '~services/envService'; import Shortcut, { ShortcutGuide, useShowDebugSwitch } from './shorcut'; const popupLogStyle = 'background:cyan;color:brown'; @@ -40,7 +41,7 @@ function IndexPopupNew() { const getTabOriginfn = useCallback(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), [TabHelper]); - const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, process.env.PLASMO_TARGET); + const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, envService.PLASMO_TARGET); const [tabSession, setTabSession] = useState(null); @@ -211,7 +212,7 @@ function IndexPopupNew() { }; const showFileUrlPermissionRequestMessage = (tabSession: TabSession, prefs, _activeTab = activeTab) => { - if (!/chrome/i.test(process.env.PLASMO_TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) { + if (!/chrome/i.test(envService.PLASMO_TARGET) || !/^file:\/\//i.test(tabSession?.origin ?? activeTab?.url) || prefs) { return null; } @@ -375,7 +376,7 @@ function IndexPopupNew() { {chrome.i18n.getMessage('shortcutLabelText')}: {chrome.i18n.getMessage( - /firefox/i.test(process.env.PLASMO_TARGET) ? 'defaultShortcutValueTextFirefox' : 'defaultShortcutValueTextChrome', + /firefox/i.test(envService.PLASMO_TARGET) ? 'defaultShortcutValueTextFirefox' : 'defaultShortcutValueTextChrome', )} */} @@ -563,7 +564,7 @@ function Footer({ textColor = 'text-secondary', chrome, onClickPasser }) {
-
{process.env.VERSION_NAME}
+
{envService.VERSION_NAME}
{/*
-
{process.env.VERSION_NAME}
+
{envService.VERSION_NAME}
diff --git a/src/popup/indexNew.tsx b/src/popup/indexNew.tsx index c0479bf..15d4ffb 100644 --- a/src/popup/indexNew.tsx +++ b/src/popup/indexNew.tsx @@ -18,6 +18,7 @@ import runTimeHandler from '~services/runTimeHandler'; import { envService } from '~services/envService'; import Shortcut, { ShortcutGuide, useShowDebugSwitch } from './shorcut'; +import { ShowDebugInline } from './ShowInlineDebug'; const popupLogStyle = 'background:cyan;color:brown'; @@ -166,35 +167,6 @@ function IndexPopupNew() { return 'animated-footer-link ' + (index === footerMessageIndex && ' animated-footer-link-show'); }; - function showDebugInline(environment = 'production') { - if (/production/i.test(environment)) return; - - const debugData = ( - <> - tabSession {JSON.stringify(tabSession)} - prefs: {JSON.stringify(prefs)} - appConfigPrefs: {JSON.stringify(appConfigPrefs)} - footerMessageIndex: {footerMessageIndex} - - ); - - return ( -
- - {isDebugDataVisible && debugData} -
- ); - } - const reloadActiveTab = async (_activeTab = activeTab) => { await chrome.tabs.reload(_activeTab.id).then(() => window.close()); }; @@ -266,9 +238,11 @@ function IndexPopupNew() { const errorOccured = !prefs || !tabSession; + console.log({ tabSession, prefs }); + return ( <> - {showDebugInline(process.env.NODE_ENV)} + {errorOccured ? ( showErrorMessage() ) : ( diff --git a/src/popup/indexOld.tsx b/src/popup/indexOld.tsx index 1e2b59f..24eee10 100644 --- a/src/popup/indexOld.tsx +++ b/src/popup/indexOld.tsx @@ -216,35 +216,6 @@ function IndexPopupOld() { ); - const showDebugInline = (environment = 'production') => { - if (/production/i.test(environment)) return; - - const debugData = ( - <> - tabSession {JSON.stringify(tabSession)} - prefs: {JSON.stringify(prefs)} - appConfigPrefs: {JSON.stringify(appConfigPrefs)} - footerMessageIndex: {footerMessageIndex} - - ); - - return ( -
- - {isDebugDataVisible && debugData} -
- ); - }; - const reloadActiveTab = async (_activeTab = activeTab) => { await chrome.tabs.reload(_activeTab.id); }; @@ -318,7 +289,8 @@ function IndexPopupOld() { return ( <> - {showDebugInline(process.env.NODE_ENV)} + + {errorOccured ? ( showErrorMessage(openSettingsPage) ) : ( From c0d5556347ae1428c6c669d14e05ceb24f65f554 Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 05:17:55 -0500 Subject: [PATCH 08/10] refactor: and cleanup --- src/contents/content.tsx | 14 ++------------ src/popup/indexOld.tsx | 15 +++++---------- src/services/usePrefs.tsx | 6 ++++++ 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/contents/content.tsx b/src/contents/content.tsx index cf41850..631399b 100644 --- a/src/contents/content.tsx +++ b/src/contents/content.tsx @@ -173,23 +173,13 @@ const IndexContent = () => {
{!prefs || !tabSession ? 'Loading... or broken but probably loading' : 'JiffyReady to the moon'}
- {JSON.stringify(tabSession)} - - {isExpanded && - prefs && - Object.entries(prefs).map(([key, val], index) => ( -

- {key}:: - {typeof val === 'boolean' ? (val === true ? 'true' : 'false') : val} -

- ))} -
+ {isExpanded &&
{JSON.stringify({ tabSession, prefs }, null, 2)}
}
{getCollapseExpandBtn()}
); }; - return showDebugOverLay(process.env.NODE_ENV !== 'production'); + return showDebugOverLay(); }; export default IndexContent; diff --git a/src/popup/indexOld.tsx b/src/popup/indexOld.tsx index 24eee10..7353db6 100644 --- a/src/popup/indexOld.tsx +++ b/src/popup/indexOld.tsx @@ -2,14 +2,13 @@ import { useEffect, useState } from 'react'; import Logger from '~services/Logger'; import TabHelper from '~services/TabHelper'; -import usePrefs from '~services/usePrefs'; +import usePrefs, { usePrefStorage } from '~services/usePrefs'; -import { useStorage } from '@plasmohq/storage'; -import type { Prefs, TabSession } from 'index'; +import type { TabSession } from 'index'; import M from 'mellowtel'; import { CONFIG_KEY, DISABLE_LOGS } from '~constants'; -import { APP_PREFS_STORE_KEY, COLOR_MODE_STATE_TRANSITIONS, DisplayColorMode, MaxSaccadesInterval, SACCADE_COLORS, SACCADE_STYLES, STORAGE_AREA } from '~services/config'; +import { COLOR_MODE_STATE_TRANSITIONS, DisplayColorMode, MaxSaccadesInterval, SACCADE_COLORS, SACCADE_STYLES } from '~services/config'; import documentParser from '~services/documentParser'; import defaultPrefs from '~services/preferences'; import runTimeHandler from '~services/runTimeHandler'; @@ -33,18 +32,14 @@ const FOOT_MESSAGAES_ANIMATION_DELAY = 300; const FIRST_FOOTER_MESSAGE_INDEX = 1; function IndexPopupOld() { - const [activeTab, setActiveTab] = useState(null as chrome.tabs.Tab); + const [activeTab, setActiveTab] = useState(null); const [footerMessageIndex, setFooterMeessageIndex] = useState(null); - const [isDebugDataVisible, setIsDebugDataVisible] = useShowDebugSwitch(); const [prefs, setPrefs] = usePrefs(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), true, envService.PLASMO_TARGET); const [tabSession, setTabSession] = useState(null); - const [appConfigPrefs, setAppConfigPrefs] = useStorage({ - key: APP_PREFS_STORE_KEY, - area: STORAGE_AREA, - }); + const [appConfigPrefs, setAppConfigPrefs] = usePrefStorage(); const footerMessagesLength = 3; const nextMessageIndex = (oldFooterMessageIndex) => (typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength); diff --git a/src/services/usePrefs.tsx b/src/services/usePrefs.tsx index ca03eec..beef80f 100644 --- a/src/services/usePrefs.tsx +++ b/src/services/usePrefs.tsx @@ -91,3 +91,9 @@ const usePrefs = (getOrigin: () => Promise, initialize = false, target = }; export default usePrefs; + +export const usePrefStorage = () => + useStorage({ + key: APP_PREFS_STORE_KEY, + area: STORAGE_AREA, + }); From 8de9f78beb0e8930d654f9f359ab7b6920cb1e5d Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 05:36:05 -0500 Subject: [PATCH 09/10] chore: refactors and cleanup with type additions --- src/popup/index.tsx | 30 ++++++++++++------------------ src/popup/indexNew.tsx | 25 +++++++++++++------------ src/popup/indexOld.tsx | 16 +++++++++------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/popup/index.tsx b/src/popup/index.tsx index c5dff27..20f4e19 100644 --- a/src/popup/index.tsx +++ b/src/popup/index.tsx @@ -1,8 +1,7 @@ -import { useCallback, useEffect, useState } from 'react'; +import { useEffect, useState, type CSSProperties } from 'react'; import Logger from '~services/Logger'; import TabHelper from '~services/TabHelper'; -import usePrefs from '~services/usePrefs'; import './../styles/style.scss'; import './style.scss'; @@ -20,7 +19,7 @@ import PopupContextProvider from './context'; import IndexPopupNew from './indexNew'; import IndexPopupOld from './indexOld'; -const badCapScroll = /safari/i.test(envService.PLASMO_TARGET) ? { overflowY: 'scroll', height: '600px' } : {}; +const badCapScroll: CSSProperties = /safari/i.test(envService.PLASMO_TARGET) ? { overflowY: 'scroll', height: '600px' } : {}; const PopupVersions = { new: IndexPopupNew, @@ -35,31 +34,25 @@ const popupLogStyle = 'background:cyan;color:brown'; const jiffyLogo = chrome.runtime.getURL('./assets/icon512.png'); -const { setAttribute, setProperty, getProperty, getAttribute, setSaccadesStyle } = documentParser.makeHandlers(document); - const SHOW_FOOTER_MESSAGE_DURATION = 12_000; const FOOT_MESSAGAES_ANIMATION_DELAY = 300; const FIRST_FOOTER_MESSAGE_INDEX = 1; function IndexPopup() { - const [activeTab, setActiveTab] = useState(null as chrome.tabs.Tab); - const [footerMessageIndex, setFooterMeessageIndex] = useState(null); - - const getTabOriginfn = useCallback(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), [TabHelper]); - - const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, envService.PLASMO_TARGET); + const [, setActiveTab] = useState(null); + const [footerMessageIndex, setFooterMeessageIndex] = useState(null); const [tabSession, setTabSession] = useState(null); - const [tipsVisibility, setTipsVisibility] = useState(false); - const [appConfigPrefs, setAppConfigPrefs] = useStorage({ key: APP_PREFS_STORE_KEY, area: STORAGE_AREA, }); const footerMessagesLength = 3; - const nextMessageIndex = (oldFooterMessageIndex) => (typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength); + + const nextMessageIndex = (oldFooterMessageIndex: typeof footerMessageIndex) => + typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength; useEffect(() => { if (!tabSession) return; @@ -77,9 +70,10 @@ function IndexPopup() { const origin = await TabHelper.getTabOrigin(_activeTab); - const brMode = chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => { - setTabSession({ brMode: data, origin }); - }); + _activeTab.id && + chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => { + setTabSession({ brMode: data, origin }); + }); })(); runTimeHandler.runtime.onMessage.addListener((request, sender, sendResponse) => { @@ -99,7 +93,7 @@ function IndexPopup() { } }); - let footerInterval; + let footerInterval: NodeJS.Timer; setTimeout(() => { setFooterMeessageIndex(nextMessageIndex); diff --git a/src/popup/indexNew.tsx b/src/popup/indexNew.tsx index 15d4ffb..6cf48a5 100644 --- a/src/popup/indexNew.tsx +++ b/src/popup/indexNew.tsx @@ -17,7 +17,7 @@ import defaultPrefs from '~services/preferences'; import runTimeHandler from '~services/runTimeHandler'; import { envService } from '~services/envService'; -import Shortcut, { ShortcutGuide, useShowDebugSwitch } from './shorcut'; +import Shortcut, { ShortcutGuide } from './shorcut'; import { ShowDebugInline } from './ShowInlineDebug'; const popupLogStyle = 'background:cyan;color:brown'; @@ -26,7 +26,7 @@ const darkToggle = chrome.runtime.getURL('./assets/moon-solid.svg'); const lightToggle = chrome.runtime.getURL('./assets/sun-light-solid.svg'); const jiffyLogo = chrome.runtime.getURL('./assets/icon512.png'); -const { setAttribute, setProperty, getProperty, getAttribute, setSaccadesStyle } = documentParser.makeHandlers(document); +const { setAttribute, setProperty, setSaccadesStyle } = documentParser.makeHandlers(document); const FIXATION_OPACITY_STOPS = 5; const FIXATION_OPACITY_STOP_UNIT_SCALE = Math.floor(100 / FIXATION_OPACITY_STOPS); @@ -36,15 +36,14 @@ const FOOT_MESSAGAES_ANIMATION_DELAY = 300; const FIRST_FOOTER_MESSAGE_INDEX = 1; function IndexPopupNew() { - const [activeTab, setActiveTab] = useState(null as chrome.tabs.Tab); - const [footerMessageIndex, setFooterMeessageIndex] = useState(null); - const [isDebugDataVisible, setIsDebugDataVisible] = useShowDebugSwitch(); + const [activeTab, setActiveTab] = useState(null); + const [footerMessageIndex, setFooterMeessageIndex] = useState(null); const getTabOriginfn = useCallback(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), [TabHelper]); const [prefs, setPrefs] = usePrefs(getTabOriginfn, true, envService.PLASMO_TARGET); - const [tabSession, setTabSession] = useState(null); + const [tabSession, setTabSession] = useState(null); const [tipsVisibility, setTipsVisibility] = useState(false); @@ -54,7 +53,8 @@ function IndexPopupNew() { }); const footerMessagesLength = 3; - const nextMessageIndex = (oldFooterMessageIndex) => (typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength); + const nextMessageIndex = (oldFooterMessageIndex: typeof footerMessageIndex) => + typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength; useEffect(() => { if (!tabSession) return; @@ -82,9 +82,10 @@ function IndexPopupNew() { const origin = await TabHelper.getTabOrigin(_activeTab); - const brMode = chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => { - setTabSession({ brMode: data, origin }); - }); + _activeTab.id && + chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => { + setTabSession({ brMode: data, origin }); + }); })(); runTimeHandler.runtime.onMessage.addListener((request, sender, sendResponse) => { @@ -104,7 +105,7 @@ function IndexPopupNew() { } }); - let footerInterval; + let footerInterval: NodeJS.Timer; setTimeout(() => { setFooterMeessageIndex(nextMessageIndex); @@ -143,7 +144,7 @@ function IndexPopupNew() { TabHelper.getActiveTab(true).then((tab) => chrome.tabs.sendMessage(tab.id, payload, () => Logger.LogLastError())); }; - const handleDisplayColorModeChange = async (currentDisplayColorMode) => { + const handleDisplayColorModeChange = async (currentDisplayColorMode: DisplayColorMode) => { console.log('handleDisplayColorModeChange', currentDisplayColorMode); if (![...Object.values(DisplayColorMode)].includes(currentDisplayColorMode)) { diff --git a/src/popup/indexOld.tsx b/src/popup/indexOld.tsx index 7353db6..5bb8c9d 100644 --- a/src/popup/indexOld.tsx +++ b/src/popup/indexOld.tsx @@ -22,7 +22,7 @@ const popupLogStyle = 'background:cyan;color:brown'; const darkToggle = chrome.runtime.getURL('./assets/moon-solid.svg'); const lightToggle = chrome.runtime.getURL('./assets/sun-light-solid.svg'); -const { setAttribute, setProperty, getProperty, getAttribute, setSaccadesStyle } = documentParser.makeHandlers(document); +const { setAttribute, setProperty, setSaccadesStyle } = documentParser.makeHandlers(document); const FIXATION_OPACITY_STOPS = 5; const FIXATION_OPACITY_STOP_UNIT_SCALE = Math.floor(100 / FIXATION_OPACITY_STOPS); @@ -37,12 +37,13 @@ function IndexPopupOld() { const [prefs, setPrefs] = usePrefs(async () => await TabHelper.getTabOrigin(await TabHelper.getActiveTab(true)), true, envService.PLASMO_TARGET); - const [tabSession, setTabSession] = useState(null); + const [tabSession, setTabSession] = useState(null); const [appConfigPrefs, setAppConfigPrefs] = usePrefStorage(); const footerMessagesLength = 3; - const nextMessageIndex = (oldFooterMessageIndex) => (typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength); + const nextMessageIndex = (oldFooterMessageIndex: typeof footerMessageIndex) => + typeof oldFooterMessageIndex !== 'number' ? FIRST_FOOTER_MESSAGE_INDEX : (oldFooterMessageIndex + 1) % footerMessagesLength; useEffect(() => { if (!tabSession) return; @@ -70,9 +71,10 @@ function IndexPopupOld() { const origin = await TabHelper.getTabOrigin(_activeTab); - const brMode = chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => { - setTabSession({ brMode: data, origin }); - }); + _activeTab.id && + chrome.tabs.sendMessage(_activeTab.id, { type: 'getReadingMode' }, ({ data }) => { + setTabSession({ brMode: data, origin }); + }); })(); runTimeHandler.runtime.onMessage.addListener((request, sender, sendResponse) => { @@ -92,7 +94,7 @@ function IndexPopupOld() { } }); - let footerInterval; + let footerInterval: NodeJS.Timer; setTimeout(() => { setFooterMeessageIndex(nextMessageIndex); From 4a9d44fcb4eceb5019d2c6e7e93e24ed508d7662 Mon Sep 17 00:00:00 2001 From: linuxdev Date: Sun, 29 Dec 2024 05:38:12 -0500 Subject: [PATCH 10/10] update: disable automatic cws publishing --- .github/workflows/publish-release.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index de9aec4..127a135 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -92,19 +92,19 @@ jobs: fi - - name: chrome ext publish - run: | - if [ -z "${{ secrets.CLIENT_ID }}" ] || [ -z "${{ secrets.CLIENT_SECRET }}" ] || [ -z "${{ secrets.REFRESH_TOKEN }}" ] || [ -z "${{ secrets.EXTENSION_ID }}" ]; then - echo "Required secrets are not provided. Exiting." - exit 0 - fi + # - name: chrome ext publish + # run: | + # if [ -z "${{ secrets.CLIENT_ID }}" ] || [ -z "${{ secrets.CLIENT_SECRET }}" ] || [ -z "${{ secrets.REFRESH_TOKEN }}" ] || [ -z "${{ secrets.EXTENSION_ID }}" ]; then + # echo "Required secrets are not provided. Exiting." + # exit 0 + # fi - npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-prod.zip ${{ secrets.EXTENSION_ID }} + # npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-prod.zip ${{ secrets.EXTENSION_ID }} - # if secrete.DEV_EXTENSION_ID is not empty then publish - if [ -n "${{ secrets.EXTENSION_DEV_ID }}" ]; then - npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-dev.zip ${{ secrets.EXTENSION_DEV_ID }} - fi + # # if secrete.DEV_EXTENSION_ID is not empty then publish + # if [ -n "${{ secrets.EXTENSION_DEV_ID }}" ]; then + # npx cws-publish ${{ secrets.CLIENT_ID }} ${{ secrets.CLIENT_SECRET }} ${{ secrets.REFRESH_TOKEN }} ./build/jiffyReader-chrome-dev.zip ${{ secrets.EXTENSION_DEV_ID }} + # fi