From bac3cb7b64a0467835bce214617cdf3561255ec1 Mon Sep 17 00:00:00 2001 From: nero120 Date: Sat, 5 Sep 2020 19:30:44 +0100 Subject: [PATCH] Added support for Brave browser (resolves #100). --- src/@types/global.d.ts | 1 + src/modules/shared/global-shared.enum.ts | 1 + src/modules/shared/utility/utility.service.ts | 4 ++++ .../chromium-platform/chromium-platform.service.ts | 5 ++++- .../webext-background/webext-background.service.ts | 13 +++++++------ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 780eb120c..6b46f4542 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -26,5 +26,6 @@ interface CordovaPlugins { } interface Navigator { + brave: any; globalization: any; } diff --git a/src/modules/shared/global-shared.enum.ts b/src/modules/shared/global-shared.enum.ts index c881d4015..5a64679f4 100644 --- a/src/modules/shared/global-shared.enum.ts +++ b/src/modules/shared/global-shared.enum.ts @@ -1,4 +1,5 @@ enum BrowserName { + Brave = 'brave', Edge = 'edge-chromium' } diff --git a/src/modules/shared/utility/utility.service.ts b/src/modules/shared/utility/utility.service.ts index 41b651745..789ea9bb0 100644 --- a/src/modules/shared/utility/utility.service.ts +++ b/src/modules/shared/utility/utility.service.ts @@ -147,6 +147,10 @@ export default class UtilityService { } } + isBraveBrowser(): boolean { + return !angular.isUndefined(window.navigator.brave); + } + isMobilePlatform(platformName: string): boolean { return platformName === PlatformType.Android; } diff --git a/src/modules/webext/chromium/chromium-shared/chromium-platform/chromium-platform.service.ts b/src/modules/webext/chromium/chromium-shared/chromium-platform/chromium-platform.service.ts index 3efa0d49f..6323e6191 100644 --- a/src/modules/webext/chromium/chromium-shared/chromium-platform/chromium-platform.service.ts +++ b/src/modules/webext/chromium/chromium-shared/chromium-platform/chromium-platform.service.ts @@ -11,7 +11,10 @@ export default class ChromiumPlatformService extends WebExtPlatformService imple platformName = PlatformType.Chromium; getNewTabUrl(): string { - switch (detectBrowser.detect().name) { + const browser = this.utilitySvc.isBraveBrowser() ? BrowserName.Brave : detectBrowser.detect().name; + switch (browser) { + case BrowserName.Brave: + return 'brave://newtab/'; case BrowserName.Edge: return 'edge://newtab/'; default: diff --git a/src/modules/webext/webext-background/webext-background.service.ts b/src/modules/webext/webext-background/webext-background.service.ts index 59cf0944a..cb588074a 100644 --- a/src/modules/webext/webext-background/webext-background.service.ts +++ b/src/modules/webext/webext-background/webext-background.service.ts @@ -8,7 +8,7 @@ import AlertService from '../../shared/alert/alert.service'; import BookmarkHelperService from '../../shared/bookmark/bookmark-helper/bookmark-helper.service'; import * as Exceptions from '../../shared/exception/exception'; import Globals from '../../shared/global-shared.constants'; -import { MessageCommand } from '../../shared/global-shared.enum'; +import { BrowserName, MessageCommand } from '../../shared/global-shared.enum'; import { Message, PlatformService } from '../../shared/global-shared.interface'; import LogService from '../../shared/log/log.service'; import NetworkService from '../../shared/network/network.service'; @@ -252,23 +252,24 @@ export default class WebExtBackgroundService { this.platformSvc.getAppVersion(), this.settingsSvc.all(), this.storeSvc.get([StoreKey.LastUpdated, StoreKey.SyncId, StoreKey.SyncVersion]), + this.upgradeSvc.checkIfUpgradeRequired(this.getCurrentVersion()), this.utilitySvc.getServiceUrl(), - this.utilitySvc.isSyncEnabled(), - this.upgradeSvc.checkIfUpgradeRequired(this.getCurrentVersion()) + this.utilitySvc.isSyncEnabled() ]) .then((data) => { const appVersion = data[0]; const settings = data[1]; const storeContent = data[2]; - const serviceUrl = data[3]; - const syncEnabled = data[4]; - const upgradeRequired = data[5]; + const upgradeRequired = data[3]; + const serviceUrl = data[4]; + const syncEnabled = data[5]; // Add useful debug info to beginning of trace log const debugInfo = angular.copy(storeContent) as any; debugInfo.appVersion = appVersion; debugInfo.checkForAppUpdates = settings.checkForAppUpdates; debugInfo.platform = detectBrowser.detect(); + debugInfo.platform.name = this.utilitySvc.isBraveBrowser() ? BrowserName.Brave : debugInfo.platform.name; debugInfo.serviceUrl = serviceUrl; debugInfo.syncBookmarksToolbar = settings.syncBookmarksToolbar; debugInfo.syncEnabled = syncEnabled;