Skip to content

Commit 88ee90e

Browse files
committed
Browser componnet
1 parent a23a6cb commit 88ee90e

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/background.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getSiteName, getMatchedEntries } from "./utils";
1212
import { CodeState } from "./models/otp";
1313

1414
import { getOTPAuthPerLineFromOPTAuthMigration } from "./models/migration";
15+
import { isChrome } from "./browser";
1516

1617
let cachedPassphrase = "";
1718
let autolockTimeout: number;
@@ -289,9 +290,7 @@ async function getTotp(text: string, silent = false) {
289290

290291
function getBackupToken(service: string) {
291292
if (
292-
navigator.userAgent.indexOf("Chrome") !== -1 &&
293-
navigator.userAgent.indexOf("Edg") === -1 &&
294-
service === "drive"
293+
isChrome && service === "drive"
295294
) {
296295
chrome.identity.getAuthToken(
297296
{
@@ -517,10 +516,7 @@ chrome.runtime.onInstalled.addListener(async (details) => {
517516

518517
let url: string | null = null;
519518

520-
if (
521-
navigator.userAgent.indexOf("Chrome") !== -1 &&
522-
navigator.userAgent.indexOf("Edg") === -1
523-
) {
519+
if (isChrome) {
524520
url = "https://otp.ee/chromeissues";
525521
}
526522

src/browser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const userAgent = navigator.userAgent;
2+
3+
export const isFirefox = (userAgent.indexOf('Firefox') >= 0);
4+
export const isWebKit = (userAgent.indexOf('AppleWebKit') >= 0);
5+
export const isChromium = (userAgent.indexOf('Chrome') >= 0);
6+
export const isSafari = (!isChromium && (userAgent.indexOf('Safari') >= 0));
7+
export const isChrome = navigator.userAgent.indexOf("Chrome") !== -1 && navigator.userAgent.indexOf("Edg") === -1;

src/components/Popup/DrivePage.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
</template>
3535
<script lang="ts">
3636
import Vue from "vue";
37+
import { isChrome } from "../../browser";
3738
import { Drive } from "../../models/backup";
3839
3940
const service = "drive";
@@ -80,10 +81,7 @@ export default Vue.extend({
8081
);
8182
xhr.onreadystatechange = () => {
8283
if (xhr.readyState === 4) {
83-
if (
84-
navigator.userAgent.indexOf("Chrome") !== -1 &&
85-
navigator.userAgent.indexOf("Edg") === -1
86-
) {
84+
if (isChrome) {
8785
chrome.identity.removeCachedAuthToken(
8886
{ token: localStorage.driveToken },
8987
() => {

src/store/Accounts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as CryptoJS from "crypto-js";
44
import { OTPType, OTPAlgorithm } from "../models/otp";
55
import { ActionContext } from "vuex";
66
import { getSiteName, getMatchedEntriesHash } from "../utils";
7-
7+
import { isChromium } from "../browser";
88
export class Accounts implements Module {
99
async getModule() {
1010
const cachedPassphrase = await this.getCachedPassphrase();
@@ -392,7 +392,7 @@ export class Accounts implements Module {
392392
await state.dispatch("updateEntries");
393393

394394
// https://github.com/Authenticator-Extension/Authenticator/issues/412
395-
if (navigator.userAgent.indexOf("Chrome") !== -1) {
395+
if (isChromium) {
396396
await BrowserStorage.clearLogs();
397397
}
398398

0 commit comments

Comments
 (0)