Skip to content

Commit

Permalink
[web] move checking for desktop Safari to constant
Browse files Browse the repository at this point in the history
Summary:
I misunderstood @tomek's suggestion from here: https://phab.comm.dev/D8124?id=27491#inline-52847

Moving not only function result to const but entire logic as this will not change during app lifetime (this is not true for tests but this is handled separately)

Test Plan:
1. Check if this const is truthy for Safari
2. Check if this const is falsy for other browser (like chrome)

Reviewers: tomek

Reviewed By: tomek

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D8226
  • Loading branch information
xsanm committed Jul 3, 2023
1 parent 4a4c8d8 commit f65a4f6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 1 addition & 3 deletions web/database/database-module-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const databaseStatuses = Object.freeze({

type DatabaseStatus = $Values<typeof databaseStatuses>;

const isSafari = isDesktopSafari();

class DatabaseModule {
worker: SharedWorker;
workerProxy: WorkerConnectionProxy;
Expand All @@ -36,7 +34,7 @@ class DatabaseModule {
: preloadedState.currentUserInfo?.id;
const isSupported = isSQLiteSupported(currentLoggedInUserID);

if (!isSupported || isSafari) {
if (!isSupported || isDesktopSafari) {
this.status = databaseStatuses.notSupported;
} else {
this.init();
Expand Down
4 changes: 1 addition & 3 deletions web/database/sqlite-data-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
import { useSelector } from '../redux/redux-utils.js';
import { workerRequestMessageTypes } from '../types/worker-types.js';

const isSafari = isDesktopSafari();

async function getSafariEncryptionKey(): Promise<SubtleCrypto$JsonWebKey> {
const encryptionKey = await localforage.getItem(SQLITE_ENCRYPTION_KEY);
if (encryptionKey) {
Expand Down Expand Up @@ -69,7 +67,7 @@ function SQLiteDataHandler(): React.Node {
(async () => {
if (currentLoggedInUserID) {
let databaseEncryptionKeyJWK = null;
if (isSafari) {
if (isDesktopSafari) {
databaseEncryptionKeyJWK = await getSafariEncryptionKey();
}
await databaseModule.initDBForLoggedInUser(
Expand Down
9 changes: 4 additions & 5 deletions web/database/utils/db-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { isDev } from 'lib/utils/dev-utils.js';

import { DB_SUPPORTED_BROWSERS, DB_SUPPORTED_OS } from './constants.js';

const browser = detectBrowser();

function parseSQLiteQueryResult<T>(result: QueryExecResult): T[] {
const { columns, values } = result;
return values.map(rowResult => {
Expand Down Expand Up @@ -38,16 +40,13 @@ function isSQLiteSupported(currentLoggedInUserID: ?string): boolean {
return false;
}

const browser = detectBrowser();
return (
DB_SUPPORTED_OS.includes(browser.os) &&
DB_SUPPORTED_BROWSERS.includes(browser.name)
);
}

function isDesktopSafari(): boolean {
const browser = detectBrowser();
return browser.name === 'safari' && browser.os === 'Mac OS';
}
const isDesktopSafari: boolean =
browser && browser.name === 'safari' && browser.os === 'Mac OS';

export { parseMultiStatementSQLiteResult, isSQLiteSupported, isDesktopSafari };

0 comments on commit f65a4f6

Please sign in to comment.