Skip to content

Commit

Permalink
feat(service-worker): refactor imports and add version-checker utility
Browse files Browse the repository at this point in the history
  • Loading branch information
arashagp committed Dec 14, 2024
1 parent 0bfbdac commit f021e89
Show file tree
Hide file tree
Showing 6 changed files with 417 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/service-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput"
},
"dependencies": {
"@alwatr/flux": "^4.0.2",
"@alwatr/i18n": "^2.0.4",
"@alwatr/local-storage": "^5.0.0",
"@alwatr/logger": "^5.0.0",
"@alwatr/package-tracer": "^5.0.0",
"@alwatr/parse-duration": "^5.0.0",
"@alwatr/wait": "^1.1.16",
"alpinejs": "^3.14.7"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/service-worker/src/lib/install-pwa.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {parseDuration} from '@alwatr/parse-duration';
import {waitForTimeout} from '@alwatr/wait';

import {snackbarSignal} from 'common/component/snackbar';
import {snackbarSignal} from '@nexim/snackbar';

import {logger} from './logger.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/service-worker/src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createLogger} from '@alwatr/logger';
import {packageTracer} from '@alwatr/package-tracer';

__dev_mode__: packageTracer.add('common/service-worker', __package_version__);
export const logger = /* @__PURE__ */ createLogger('common/service-worker');
__dev_mode__: packageTracer.add(__package_name__, __package_version__);
export const logger = /* @__PURE__ */ createLogger(`${__package_name__}:service-worker`);
4 changes: 2 additions & 2 deletions packages/service-worker/src/lib/service-worker-notify.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {l10n} from '@alwatr/i18n';
import {snackbarSignal} from '@nexim/snackbar';

import {snackbarSignal} from 'common/component/snackbar';
import {isVersionLarger} from 'common/util';

import {logger} from './logger.js';
import {serviceWorkerSignal} from './service-worker.js';
import {isVersionLarger} from './version-checker.js';

const notifyLocalStorageKey = 'notify_new_version';

Expand Down
14 changes: 14 additions & 0 deletions packages/service-worker/src/lib/version-checker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { logger } from "./logger.js";

export function isVersionLarger(currentVersion: string, otherVersion: string) {
logger.logMethodArgs?.('isVersionLarger', {currentVersion, otherVersion});
const current = currentVersion.split('.').map(Number);
const other = otherVersion.split('.').map(Number);

for (let i = 0; i < 3; i++) {
if (current[i] > other[i]) return true;
if (current[i] < other[i]) return false;
}

return false;
}
Loading

0 comments on commit f021e89

Please sign in to comment.