diff --git a/dev-dist/registerSW.js b/dev-dist/registerSW.js
new file mode 100644
index 00000000..fdeaac12
--- /dev/null
+++ b/dev-dist/registerSW.js
@@ -0,0 +1 @@
+if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'module' })
\ No newline at end of file
diff --git a/electron/preload.mjs b/electron/preload.mjs
index c542bd61..f35cdc48 100644
--- a/electron/preload.mjs
+++ b/electron/preload.mjs
@@ -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 });
\ No newline at end of file
diff --git a/package.json b/package.json
index 9ff4daf0..6c8c6bad 100644
--- a/package.json
+++ b/package.json
@@ -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}",
diff --git a/src/components/settings-modal/account-settings/account-settings.tsx b/src/components/settings-modal/account-settings/account-settings.tsx
index 3d360b58..f7b06134 100644
--- a/src/components/settings-modal/account-settings/account-settings.tsx
+++ b/src/components/settings-modal/account-settings/account-settings.tsx
@@ -228,7 +228,7 @@ const AccountSettings = () => {
{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 },
})}
diff --git a/src/components/settings-modal/interface-settings/interface-settings.tsx b/src/components/settings-modal/interface-settings/interface-settings.tsx
index 81c17939..b671c104 100644
--- a/src/components/settings-modal/interface-settings/interface-settings.tsx
+++ b/src/components/settings-modal/interface-settings/interface-settings.tsx
@@ -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();
diff --git a/src/components/settings-modal/plebbit-options/plebbit-options.tsx b/src/components/settings-modal/plebbit-options/plebbit-options.tsx
index b6ccb5ae..ad640674 100644
--- a/src/components/settings-modal/plebbit-options/plebbit-options.tsx
+++ b/src/components/settings-modal/plebbit-options/plebbit-options.tsx
@@ -134,7 +134,7 @@ const PlebbitDataPathSettings = ({ plebbitDataPathRef }: SettingsProps) => {
);
};
-const isElectron = window.isElectron === true;
+const isElectron = window.electronApi?.isElectron === true;
const PlebbitOptions = () => {
const { t } = useTranslation();
diff --git a/src/components/version/version.tsx b/src/components/version/version.tsx
index 3cd3466e..bbfb9ec0 100644
--- a/src/components/version/version.tsx
+++ b/src/components/version/version.tsx
@@ -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 (
<>
{
target='_blank'
rel='noopener noreferrer'
>
- plebchan v{commitRef ? `${version}-dev (#${commitRef.slice(0, 7)})` : version}
+ v{commitRef ? `${version}#${commitRef.slice(0, 7)}` : version}
{isElectron && (
<>
diff --git a/src/env.d.ts b/src/env.d.ts
new file mode 100644
index 00000000..282e5be5
--- /dev/null
+++ b/src/env.d.ts
@@ -0,0 +1,9 @@
+///
+
+declare interface ImportMetaEnv {
+ readonly VITE_COMMIT_REF: string;
+}
+
+declare interface ImportMeta {
+ readonly env: ImportMetaEnv;
+}
diff --git a/src/globals.d.ts b/src/globals.d.ts
index 85b49151..d0d7a7f5 100644
--- a/src/globals.d.ts
+++ b/src/globals.d.ts
@@ -4,4 +4,16 @@ declare global {
}
}
+declare global {
+ interface Window {
+ electronApi?: {
+ isElectron: boolean;
+ invoke: (channel: string, ...args: any[]) => Promise;
+ getNotificationStatus: () => Promise<'granted' | 'denied' | 'not-determined' | 'not-supported'>;
+ getPlatform: () => Promise;
+ testNotification: () => Promise<{ success: boolean; reason?: string }>;
+ };
+ }
+}
+
export {};
diff --git a/src/sw.ts b/src/sw.ts
new file mode 100644
index 00000000..e404928f
--- /dev/null
+++ b/src/sw.ts
@@ -0,0 +1,15 @@
+///
+/* 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();
diff --git a/vite.config.js b/vite.config.js
index c5f0881b..8895673b 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -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',