fix env, sw, pwa

This commit is contained in:
Tom (plebeius.eth)
2025-05-22 17:42:04 +02:00
parent facd20d4c2
commit 0a5f868747
11 changed files with 56 additions and 8 deletions
+1
View File
@@ -0,0 +1 @@
if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'module' })
+2
View File
@@ -15,3 +15,5 @@ contextBridge.exposeInMainWorld('defaultMediaIpfsGatewayUrl', 'http://localhost:
// receive plebbit rpc auth key from main
ipcRenderer.on('plebbit-rpc-auth-key', (event, plebbitRpcAuthKey) => contextBridge.exposeInMainWorld('plebbitRpcAuthKey', plebbitRpcAuthKey));
ipcRenderer.send('get-plebbit-rpc-auth-key');
contextBridge.exposeInMainWorld('electronApi', { isElectron: true });
+1 -1
View File
@@ -127,7 +127,7 @@
"appId": "plebchan.desktop",
"productName": "plebchan",
"beforePack": "electron/before-pack.js",
"afterAllArtifactBuild": "electron/after-all-artifact-build.js",
"afterAllArtifactBuild": "electron/after-all-artifact-build.cjs",
"extraResources": [
{
"from": "bin/${os}",
@@ -228,7 +228,7 @@ const AccountSettings = () => {
<button onClick={handleImportAccount}>{t('import')}</button> <button onClick={handleExportAccount}>{t('export')}</button>
<div className={styles.warning}>
{t('stored_locally', {
location: window.isElectron ? 'this desktop app' : isAndroid ? 'this mobile app' : window.location.hostname,
location: window.electronApi?.isElectron ? 'this desktop app' : isAndroid ? 'this mobile app' : window.location.hostname,
interpolation: { escapeValue: false },
})}
</div>
@@ -13,7 +13,7 @@ import { isChristmas } from '../../../lib/utils/time-utils';
import Version from '../../version';
const commitRef = process.env.VITE_COMMIT_REF;
const isElectron = window.isElectron === true;
const isElectron = window.electronApi?.isElectron === true;
const CheckForUpdates = () => {
const { t } = useTranslation();
@@ -134,7 +134,7 @@ const PlebbitDataPathSettings = ({ plebbitDataPathRef }: SettingsProps) => {
);
};
const isElectron = window.isElectron === true;
const isElectron = window.electronApi?.isElectron === true;
const PlebbitOptions = () => {
const { t } = useTranslation();
+3 -4
View File
@@ -2,12 +2,11 @@ import { useTranslation } from 'react-i18next';
import packageJson from '../../../package.json';
const { version } = packageJson;
const commitRef = process.env.VITE_COMMIT_REF;
const isElectron = window.isElectron === true;
const commitRef = import.meta.env.VITE_COMMIT_REF;
const isElectron = window.electronApi?.isElectron === true;
const Version = () => {
const { t } = useTranslation();
return (
<>
<a
@@ -15,7 +14,7 @@ const Version = () => {
target='_blank'
rel='noopener noreferrer'
>
plebchan v{commitRef ? `${version}-dev (#${commitRef.slice(0, 7)})` : version}
v{commitRef ? `${version}#${commitRef.slice(0, 7)}` : version}
</a>
{isElectron && (
<>
+9
View File
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />
declare interface ImportMetaEnv {
readonly VITE_COMMIT_REF: string;
}
declare interface ImportMeta {
readonly env: ImportMetaEnv;
}
+12
View File
@@ -4,4 +4,16 @@ declare global {
}
}
declare global {
interface Window {
electronApi?: {
isElectron: boolean;
invoke: (channel: string, ...args: any[]) => Promise<any>;
getNotificationStatus: () => Promise<'granted' | 'denied' | 'not-determined' | 'not-supported'>;
getPlatform: () => Promise<NodeJS.Platform>;
testNotification: () => Promise<{ success: boolean; reason?: string }>;
};
}
}
export {};
+15
View File
@@ -0,0 +1,15 @@
/// <reference lib="webworker" />
/* eslint-disable no-restricted-globals */
import { clientsClaim } from 'workbox-core';
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
declare const self: ServiceWorkerGlobalScope;
// Precache all assets specified in the manifest
cleanupOutdatedCaches();
precacheAndRoute(self.__WB_MANIFEST);
// Standard SW lifecycle methods
self.skipWaiting();
clientsClaim();
+10
View File
@@ -36,6 +36,16 @@ export default defineConfig({
}),
VitePWA({
registerType: 'autoUpdate',
strategies: 'injectManifest',
injectManifest: {
maximumFileSizeToCacheInBytes: 6000000,
},
srcDir: 'src',
filename: 'sw.ts',
devOptions: {
enabled: true,
type: 'module',
},
includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
manifest: {
name: 'Seedit',