Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3389515
D9633.id32565.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D9633.id32565.diff
View Options
diff --git a/web/database/database-module-provider.js b/web/database/database-module-provider.js
--- a/web/database/database-module-provider.js
+++ b/web/database/database-module-provider.js
@@ -5,7 +5,7 @@
import {
DATABASE_WORKER_PATH,
- DATABASE_MODULE_FILE_PATH,
+ WORKERS_MODULES_FILE_PATH,
SQLITE_ENCRYPTION_KEY,
} from './utils/constants.js';
import { isDesktopSafari, isSQLiteSupported } from './utils/db-utils.js';
@@ -88,7 +88,7 @@
invariant(this.workerProxy, 'Worker proxy should exist');
await this.workerProxy.scheduleOnWorker({
type: workerRequestMessageTypes.INIT,
- databaseModuleFilePath: `${origin}${baseURL}${DATABASE_MODULE_FILE_PATH}`,
+ databaseModuleFilePath: `${origin}${baseURL}${WORKERS_MODULES_FILE_PATH}`,
encryptionKey,
commQueryExecutorFilename,
});
diff --git a/web/database/utils/constants.js b/web/database/utils/constants.js
--- a/web/database/utils/constants.js
+++ b/web/database/utils/constants.js
@@ -8,10 +8,12 @@
export const CURRENT_USER_ID_KEY = 'current_user_id';
export const DATABASE_WORKER_PATH = 'worker/database';
-export const DATABASE_MODULE_FILE_PATH = '/compiled/webworkers';
+export const WORKERS_MODULES_FILE_PATH = '/compiled/webworkers';
export const DEFAULT_COMM_QUERY_EXECUTOR_FILENAME = 'comm_query_executor.wasm';
+export const DEFAULT_OLM_FILENAME = 'olm.wasm';
+
export const COMM_SQLITE_DATABASE_PATH = 'comm.sqlite';
export const NOTIFICATIONS_OLM_SESSION_CONTENT =
diff --git a/web/push-notif/notif-crypto-utils.js b/web/push-notif/notif-crypto-utils.js
new file mode 100644
--- /dev/null
+++ b/web/push-notif/notif-crypto-utils.js
@@ -0,0 +1,3 @@
+// @flow
+
+export const OLM_WASM_PATH_KEY = 'olmWasmPath';
diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js
--- a/web/push-notif/push-notifs-handler.js
+++ b/web/push-notif/push-notifs-handler.js
@@ -20,11 +20,17 @@
} from 'lib/utils/push-alerts.js';
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
+import {
+ WORKERS_MODULES_FILE_PATH,
+ DEFAULT_OLM_FILENAME,
+} from '../database/utils/constants.js';
import electron from '../electron.js';
import PushNotifModal from '../modals/push-notif-modal.react.js';
import { updateNavInfoActionType } from '../redux/action-types.js';
import { useSelector } from '../redux/redux-utils.js';
+declare var baseURL: string;
+
function useCreateDesktopPushSubscription() {
const dispatchActionPromise = useDispatchActionPromise();
const callSetDeviceToken = useServerCall(setDeviceToken);
@@ -78,6 +84,11 @@
return;
}
+ const origin = window.location.origin;
+ const olmDirPath = `${origin}${baseURL}${WORKERS_MODULES_FILE_PATH}`;
+ const olmFilePath = `${olmDirPath}/${DEFAULT_OLM_FILENAME}`;
+ workerRegistration.active?.postMessage({ olmFilePath });
+
const subscription = await workerRegistration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: publicKey,
diff --git a/web/push-notif/service-worker.js b/web/push-notif/service-worker.js
--- a/web/push-notif/service-worker.js
+++ b/web/push-notif/service-worker.js
@@ -1,9 +1,14 @@
// @flow
+import localforage from 'localforage';
+
import type { PlainTextWebNotification } from 'lib/types/notif-types.js';
import { convertNonPendingIDToNewSchema } from 'lib/utils/migration-utils.js';
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
+import { OLM_WASM_PATH_KEY } from './notif-crypto-utils.js';
+import { localforageConfig } from '../database/utils/constants.js';
+
declare class PushMessageData {
json(): Object;
}
@@ -11,6 +16,10 @@
+data: PushMessageData;
}
+declare class CommAppMessage extends ExtendableEvent {
+ +data: { +olmFilePath?: string };
+}
+
declare var clients: Clients;
declare function skipWaiting(): Promise<void>;
@@ -22,6 +31,18 @@
event.waitUntil(clients.claim());
});
+self.addEventListener('message', (event: CommAppMessage) => {
+ localforage.config(localforageConfig);
+ event.waitUntil(
+ (async () => {
+ if (!event.data.olmFilePath) {
+ return;
+ }
+ await localforage.setItem(OLM_WASM_PATH_KEY, event.data.olmFilePath);
+ })(),
+ );
+});
+
self.addEventListener('push', (event: PushEvent) => {
const data: PlainTextWebNotification = event.data.json();
diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs
--- a/web/webpack.config.cjs
+++ b/web/webpack.config.cjs
@@ -145,6 +145,14 @@
},
],
}),
+ new CopyPlugin({
+ patterns: [
+ {
+ from: 'node_modules/@commapp/olm/olm.wasm',
+ to: path.join(__dirname, 'dist', 'webworkers'),
+ },
+ ],
+ }),
];
const prodWebWorkersPlugins = [
@@ -161,6 +169,19 @@
},
],
}),
+ new CopyPlugin({
+ patterns: [
+ {
+ from: 'node_modules/@commapp/olm/olm.wasm',
+ to: path.join(
+ __dirname,
+ 'dist',
+ 'webworkers',
+ 'olm.[contenthash:12].wasm',
+ ),
+ },
+ ],
+ }),
new WebpackManifestPlugin({
publicPath: '',
}),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 7:27 PM (21 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2602115
Default Alt Text
D9633.id32565.diff (5 KB)
Attached To
Mode
D9633: Expose olm WASM to push notif service-worker on web.
Attached
Detach File
Event Timeline
Log In to Comment