Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/modules/shared/alert/alert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { Alert } from './alert.interface';
@Injectable('AlertService')
export class AlertService {
private _currentAlert: Alert | undefined;
onAlertChanged?: (alert: Alert) => void;

get currentAlert(): Alert | undefined {
return this._currentAlert;
}

set currentAlert(value: Alert) {
this._currentAlert = value;
this.onAlertChanged?.(value);
}

clearCurrentAlert(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import angular from 'angular';
import { NgModule } from 'angular-ts-decorators';
import { WebExtBackgroundModule } from '../../webext-background/webext-background.module';
/**
* Chromium background entry point for MV3 service worker.
* Replaces the AngularJS bootstrap with a manual DI container.
*/

import browser from 'webextension-polyfill';
import { WebExtV160UpgradeProviderService } from '../../shared/webext-upgrade/webext-v1.6.0-upgrade-provider.service';
import { setupAngularShim } from '../../webext-background/angular-shims';
import { createBackgroundContainer } from '../../webext-background/background-container';
import { ChromiumBookmarkService } from '../shared/chromium-bookmark/chromium-bookmark.service';
import { ChromiumPlatformService } from '../shared/chromium-platform/chromium-platform.service';

@NgModule({
id: 'ChromiumBackgroundModule',
imports: [WebExtBackgroundModule],
providers: [ChromiumBookmarkService, ChromiumPlatformService]
})
class ChromiumBackgroundModule {}
// Set up angular shim before any service code runs
setupAngularShim();

// Mark this as the background context
// eslint-disable-next-line no-undef, no-restricted-globals
(self as any).__xbs_isBackground = true;

// Create the DI container with Chromium-specific services
const { backgroundSvc } = createBackgroundContainer({
BookmarkServiceClass: ChromiumBookmarkService,
PlatformServiceClass: ChromiumPlatformService,
UpgradeProviderServiceClass: WebExtV160UpgradeProviderService
});

// Register event handlers synchronously (required for MV3 service workers)
let startupInitiated = false;

browser.runtime.onInstalled.addListener((details) => {
if (startupInitiated) return;
startupInitiated = true;
backgroundSvc.onInstall(details.reason);
});

angular.element(document).ready(() => {
angular.bootstrap(document, [(ChromiumBackgroundModule as NgModule).module.name]);
browser.runtime.onStartup.addListener(() => {
if (startupInitiated) return;
startupInitiated = true;
backgroundSvc.init();
});
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import angular from 'angular';
import { NgModule } from 'angular-ts-decorators';
/**
* Firefox background entry point for MV3 background scripts.
* Replaces the AngularJS bootstrap with a manual DI container.
*/

import browser from 'webextension-polyfill';
import { WebExtBackgroundModule } from '../../webext-background/webext-background.module';
import { WebExtV160UpgradeProviderService } from '../../shared/webext-upgrade/webext-v1.6.0-upgrade-provider.service';
import { setupAngularShim } from '../../webext-background/angular-shims';
import { createBackgroundContainer } from '../../webext-background/background-container';
import { FirefoxBookmarkService } from '../shared/firefox-bookmark/firefox-bookmark.service';
import { FirefoxPlatformService } from '../shared/firefox-platform/firefox-platform.service';

@NgModule({
id: 'FirefoxBackgroundModule',
imports: [WebExtBackgroundModule],
providers: [FirefoxBookmarkService, FirefoxPlatformService]
})
class FirefoxBackgroundModule {}
// Set up angular shim before any service code runs
setupAngularShim();

(FirefoxBackgroundModule as NgModule).module.config([
'$compileProvider',
'$httpProvider',
($compileProvider: ng.ICompileProvider, $httpProvider: ng.IHttpProvider) => {
$compileProvider.debugInfoEnabled(false);
$httpProvider.interceptors.push('ApiRequestInterceptorFactory');
}
]);
// Mark this as the background context
// eslint-disable-next-line no-undef, no-restricted-globals
(self as any).__xbs_isBackground = true;

angular.element(document).ready(() => {
angular.bootstrap(document, [(FirefoxBackgroundModule as NgModule).module.name]);
// Create the DI container with Firefox-specific services
const { backgroundSvc } = createBackgroundContainer({
BookmarkServiceClass: FirefoxBookmarkService,
PlatformServiceClass: FirefoxPlatformService,
UpgradeProviderServiceClass: WebExtV160UpgradeProviderService
});

// Set synchronous event handlers
// Register event handlers synchronously (required for MV3 background scripts)
let startupInitiated = false;

browser.runtime.onInstalled.addListener((details) => {
// Store event details as element data
const element = document.querySelector('#install');
angular.element(element).data('details', details);
(document.querySelector('#install') as HTMLButtonElement).click();
if (startupInitiated) return;
startupInitiated = true;
backgroundSvc.onInstall(details.reason);
});

browser.runtime.onStartup.addListener(() => {
(document.querySelector('#startup') as HTMLButtonElement).click();
if (startupInitiated) return;
startupInitiated = true;
backgroundSvc.init();
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import angular from 'angular';
import { boundMethod } from 'autobind-decorator';
import * as detectBrowser from 'detect-browser';
import browser, { Tabs } from 'webextension-polyfill';
Expand Down Expand Up @@ -87,7 +86,7 @@ export abstract class WebExtPlatformService implements PlatformService {
platformName = '';

get backgroundSvc(): WebExtBackgroundService {
if (angular.isUndefined(this._backgroundSvc)) {
if (this._backgroundSvc === undefined) {
this._backgroundSvc = this.$injector.get('WebExtBackgroundService');
}
return this._backgroundSvc as WebExtBackgroundService;
Expand Down Expand Up @@ -165,7 +164,7 @@ export abstract class WebExtPlatformService implements PlatformService {
i18nStr = browser.i18n.getMessage(`${i18nObj.key}_Default`);
}

if (angular.isUndefined(i18nStr ?? undefined)) {
if ((i18nStr ?? undefined) === undefined) {
throw new I18nError('I18n string has no value');
}

Expand Down Expand Up @@ -308,7 +307,7 @@ export abstract class WebExtPlatformService implements PlatformService {
const iconUpdated = this.$q.defer<void>();
const titleUpdated = this.$q.defer<void>();

browser.browserAction.getTitle({}).then((currentTitle) => {
(browser.action || browser.browserAction).getTitle({}).then((currentTitle) => {
// Don't do anything if browser action title hasn't changed
if (newTitle === currentTitle) {
return resolve();
Expand All @@ -317,14 +316,14 @@ export abstract class WebExtPlatformService implements PlatformService {
// Set a delay if finished syncing to prevent flickering when executing many syncs
if (currentTitle.indexOf(syncingTitle) > 0 && newTitle.indexOf(syncedTitle)) {
this.refreshInterfaceTimeout = this.$timeout(() => {
browser.browserAction.setIcon({ path: iconPath });
browser.browserAction.setTitle({ title: newTitle });
(browser.action || browser.browserAction).setIcon({ path: iconPath });
(browser.action || browser.browserAction).setTitle({ title: newTitle });
}, 350);
iconUpdated.resolve();
titleUpdated.resolve();
} else {
browser.browserAction.setIcon({ path: iconPath }).then(iconUpdated.resolve);
browser.browserAction.setTitle({ title: newTitle }).then(titleUpdated.resolve);
(browser.action || browser.browserAction).setIcon({ path: iconPath }).then(iconUpdated.resolve);
(browser.action || browser.browserAction).setTitle({ title: newTitle }).then(titleUpdated.resolve);
}

this.$q.all([iconUpdated, titleUpdated]).then(resolve).catch(reject);
Expand All @@ -333,17 +332,13 @@ export abstract class WebExtPlatformService implements PlatformService {
}

sendMessage(message: Message): ng.IPromise<any> {
// If background module loaded use browser API to send the message
let module: ng.IModule | undefined;
try {
module = angular.module('WebExtBackgroundModule');
} catch (err) {}

// If running in background context, call service directly; otherwise use browser messaging API
let promise: ng.IPromise<any>;
if (angular.isUndefined(module)) {
promise = browser.runtime.sendMessage(message);
} else {
// eslint-disable-next-line no-undef, no-restricted-globals
if ((self as any).__xbs_isBackground) {
promise = this.backgroundSvc.onMessage(message);
} else {
promise = browser.runtime.sendMessage(message);
}

return promise.catch((err: Error) => {
Expand Down
Loading
Loading