diff --git a/src/lib/Controller.ts b/src/lib/Controller.ts index d0b2fac6..9a8cb1e9 100644 --- a/src/lib/Controller.ts +++ b/src/lib/Controller.ts @@ -1,11 +1,22 @@ import IController from './interfaces/Controller' +import { Capacitor } from '@capacitor/core' export default class Controller implements IController { static singleton: IController static async getSingleton():Promise { if (!this.singleton) { - this.singleton = new Controller + // eslint-disable-next-line no-undef + if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { + if (Capacitor.getPlatform() === 'web') { + this.singleton = new (await import('./browser/BrowserController')).default + } else { + this.singleton = new (await import('./native/NativeController')).default + } + return this.singleton + } else { + this.singleton = new Controller + } } return this.singleton } @@ -54,7 +65,7 @@ export default class Controller implements IController { syncAccount(accountId, strategy): Promise { return navigator.serviceWorker.ready.then((registration) => { const worker = registration.active - worker.postMessage({type: 'setEnabled', params: [accountId, strategy]}) + worker.postMessage({type: 'syncAccount', params: [accountId, strategy]}) }) } diff --git a/src/lib/browser/BrowserController.js b/src/lib/browser/BrowserController.js index 6e8f948e..a88b70fc 100644 --- a/src/lib/browser/BrowserController.js +++ b/src/lib/browser/BrowserController.js @@ -372,7 +372,7 @@ export default class BrowserController { } if (icon[status]) { - await browser.browserAction.setIcon(icon[status]) + await browser.action.setIcon(icon[status]) } } diff --git a/tsconfig.json b/tsconfig.json index ba380126..ceb19092 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,14 @@ "noImplicitThis": true, "esModuleInterop": true, "resolveJsonModule": true, - "lib": ["DOM" ,"es2015", "es2016", "es2017", "es2019"] + "lib": [ + "DOM", + "es2015", + "es2016", + "es2017", + "es2019", + "webworker" + ] }, "exclude": [ "node_modules",