Skip to content

Commit 0d7f09a

Browse files
authored
Merge pull request #923 from rebornix/rebornix/safari
2 parents d34f98b + db17b3d commit 0d7f09a

File tree

15 files changed

+206
-46
lines changed

15 files changed

+206
-46
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
> Authenticator generates 2-Step Verification codes in your browser.
44
5-
## Available for Chrome, Firefox, and Microsoft Edge
5+
## Available for Chrome, Firefox, Microsoft Edge and Safari
66

7-
[<img src="https://raw.githubusercontent.com/wiki/Authenticator-Extension/Authenticator/readme-images/chrome-web-store.png" title="Chrome Web Store" width="170" height="48" />](https://chrome.google.com/webstore/detail/authenticator/bhghoamapcdpbohphigoooaddinpkbai) [<img src="https://raw.githubusercontent.com/wiki/Authenticator-Extension/Authenticator/readme-images/firefox-add-ons.png" title="Firefox Add-ons" width="170" height="48" />](https://addons.mozilla.org/en-US/firefox/addon/auth-helper?src=external-github) [<img src="https://raw.githubusercontent.com/wiki/Authenticator-Extension/Authenticator/readme-images/microsoft-store.png" title="Microsoft Store" height="48">](https://microsoftedge.microsoft.com/addons/detail/ocglkepbibnalbgmbachknglpdipeoio)
7+
[<img src="https://raw.githubusercontent.com/wiki/Authenticator-Extension/Authenticator/readme-images/chrome-web-store.png" title="Chrome Web Store" width="170" height="48" />](https://chrome.google.com/webstore/detail/authenticator/bhghoamapcdpbohphigoooaddinpkbai) [<img src="https://raw.githubusercontent.com/wiki/Authenticator-Extension/Authenticator/readme-images/firefox-add-ons.png" title="Firefox Add-ons" width="170" height="48" />](https://addons.mozilla.org/en-US/firefox/addon/auth-helper?src=external-github) [<img src="https://raw.githubusercontent.com/wiki/Authenticator-Extension/Authenticator/readme-images/microsoft-store.png" title="Microsoft Store" height="48">](https://microsoftedge.microsoft.com/addons/detail/ocglkepbibnalbgmbachknglpdipeoio) [<img width="150" alt="Download on the App Store" src="https://developer.apple.com/assets/elements/badges/download-on-the-app-store.svg"/>](https://apps.apple.com/us/app/authen/id1602945200?mt=12)
88

99
## Build Setup
1010

@@ -22,6 +22,8 @@ npm ci
2222
npm run prod
2323
```
2424

25+
To reproduce a build for Safari, please follow contribution guidance in [Authenticator-Extension/Authen](https://github.com/Authenticator-Extension/Authen#how-to-contribute)
26+
2527
## Development (Chrome)
2628

2729
``` bash

_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@
317317
"message": "High Contrast",
318318
"description": "High Contrast theme"
319319
},
320+
"theme_flat": {
321+
"message": "Flat",
322+
"description": "Flat theme"
323+
},
320324
"storage_sync_info": {
321325
"message": "Automatically backup your data to 3rd party storage services.",
322326
"description": "3rd party backup info"

sass/_ui.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ $themes: (
9999
grey-search: #b1b1b3,
100100
blue-menu: #f4fcff,
101101
),
102+
flat: (
103+
black-1: black,
104+
black-transparent: rgba(0, 0, 0, 0.5),
105+
white-1: white,
106+
white-transparent: rgba(255, 255, 255, 0.5),
107+
grey-1: grey,
108+
grey-2: #ccc,
109+
grey-3: #eee,
110+
grey-background: #eee,
111+
blue-1: #08c,
112+
yellow-1: #fff1ba,
113+
yellow-2: #fff4cc,
114+
red-1: #dd4b39,
115+
red-2: #eea59c,
116+
black-search: #2a2a2e,
117+
white-search: #f9f9fa,
118+
grey-search: #b1b1b3,
119+
blue-menu: #f4fcff,
120+
),
102121
);
103122

104123
$theme-map: null;

sass/popup.scss

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,3 +1306,64 @@ svg {
13061306
border: 2px solid black !important;
13071307
}
13081308
}
1309+
1310+
// Flat overrides
1311+
.theme-flat {
1312+
.header {
1313+
color: black;
1314+
background: white;
1315+
border-bottom: #f5f4f7 1px solid;
1316+
}
1317+
1318+
#codes {
1319+
background: #fcfbff;
1320+
1321+
.entry {
1322+
border: #f5f4f7 1px solid;
1323+
border-radius: 8px;
1324+
}
1325+
}
1326+
1327+
#menu {
1328+
#menuBody {
1329+
background: #fcfbff;
1330+
1331+
.menuList {
1332+
margin: 10px;
1333+
border-radius: 8px;
1334+
border: #f5f4f7 1px solid;
1335+
background: white;
1336+
1337+
p {
1338+
color: #727272;
1339+
1340+
&:not(:last-child) {
1341+
border-bottom: #f5f4f7 1px solid;
1342+
}
1343+
1344+
span svg {
1345+
fill: #727272;
1346+
}
1347+
}
1348+
}
1349+
}
1350+
1351+
#version {
1352+
bottom: 0px;
1353+
position: relative;
1354+
margin: 10px auto;
1355+
width: 100%;
1356+
color: #727272;
1357+
font-size: 0.9em;
1358+
}
1359+
1360+
#info {
1361+
border-radius: 8px;
1362+
border: #f5f4f7 1px solid;
1363+
1364+
.control-group {
1365+
border-bottom: #f5f4f7 1px solid;
1366+
}
1367+
}
1368+
}
1369+
}

src/background.ts

Lines changed: 6 additions & 12 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, isFirefox } from "./browser";
1516

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

290291
function getBackupToken(service: string) {
291-
if (
292-
navigator.userAgent.indexOf("Chrome") !== -1 &&
293-
navigator.userAgent.indexOf("Edg") === -1 &&
294-
service === "drive"
295-
) {
292+
if (isChrome && service === "drive") {
296293
chrome.identity.getAuthToken(
297294
{
298295
interactive: true,
@@ -320,7 +317,7 @@ function getBackupToken(service: string) {
320317
} else if (service === "drive") {
321318
if (navigator.userAgent.indexOf("Edg") !== -1) {
322319
redirUrl = encodeURIComponent("https://authenticator.cc/oauth-edge");
323-
} else if (navigator.userAgent.indexOf("Firefox") !== -1) {
320+
} else if (isFirefox) {
324321
redirUrl = encodeURIComponent(chrome.identity.getRedirectURL());
325322
} else {
326323
redirUrl = encodeURIComponent("https://authenticator.cc/oauth");
@@ -415,7 +412,7 @@ function getBackupToken(service: string) {
415412
}
416413
} catch (error) {
417414
console.error(error);
418-
reject(error);
415+
reject(error as Error);
419416
}
420417
}
421418
return;
@@ -517,10 +514,7 @@ chrome.runtime.onInstalled.addListener(async (details) => {
517514

518515
let url: string | null = null;
519516

520-
if (
521-
navigator.userAgent.indexOf("Chrome") !== -1 &&
522-
navigator.userAgent.indexOf("Edg") === -1
523-
) {
517+
if (isChrome) {
524518
url = "https://otp.ee/chromeissues";
525519
}
526520

@@ -664,7 +658,7 @@ function updateContextMenu() {
664658
encodeURIComponent(tab.title);
665659
}
666660
let windowType;
667-
if (navigator.userAgent.indexOf("Firefox") !== -1) {
661+
if (isFirefox) {
668662
windowType = "detached_panel";
669663
} else {
670664
windowType = "panel";

src/browser.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 isEdge = navigator.userAgent.indexOf("Edg") >= 0;
6+
export const isChromium = userAgent.indexOf("Chrome") >= 0;
7+
export const isSafari = !isChromium && userAgent.indexOf("Safari") >= 0;
8+
export const isChrome =
9+
navigator.userAgent.indexOf("Chrome") !== -1 &&
10+
navigator.userAgent.indexOf("Edg") === -1;

src/components/Popup.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
theme !== 'accessibility' &&
77
theme !== 'dark' &&
88
theme !== 'simple' &&
9-
theme !== 'compact',
9+
theme !== 'compact' &&
10+
theme !== 'flat',
1011
'theme-accessibility': theme === 'accessibility',
1112
'theme-dark': theme === 'dark',
1213
'theme-simple': theme === 'simple',
1314
'theme-compact': theme === 'compact',
15+
'theme-flat': theme === 'flat',
1416
hideoutline,
1517
}"
1618
v-on:mousedown="hideoutline = true"

src/components/Popup/BackupPage.vue

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,47 @@
1717
<a-button-link
1818
download="authenticator.txt"
1919
:href="exportOneLineOtpAuthFile"
20-
v-if="!unsupportedAccounts"
20+
v-if="!unsupportedAccounts && isDataLinkSupported"
2121
>{{ i18n.download_backup }}</a-button-link
2222
>
23-
<a-button-link download="authenticator.json" :href="exportFile" v-else>{{
24-
i18n.download_backup
25-
}}</a-button-link>
23+
<button
24+
v-on:click="downloadBackUpOneLineOtpAuthFile()"
25+
v-if="!unsupportedAccounts && !isDataLinkSupported"
26+
class="button"
27+
>
28+
{{ i18n.download_backup }}
29+
</button>
30+
<a-button-link
31+
download="authenticator.json"
32+
:href="exportFile"
33+
v-if="unsupportedAccounts && isDataLinkSupported"
34+
>{{ i18n.download_backup }}</a-button-link
35+
>
36+
<button
37+
v-on:click="downloadBackUpExportFile()"
38+
v-if="unsupportedAccounts && !isDataLinkSupported"
39+
class="button"
40+
>
41+
{{ i18n.download_backup }}
42+
</button>
2643
<a-button-link
2744
download="authenticator.json"
2845
:href="exportEncryptedFile"
29-
v-if="encryption.getEncryptionStatus()"
46+
v-if="encryption.getEncryptionStatus() && isDataLinkSupported"
3047
>{{ i18n.download_enc_backup }}</a-button-link
3148
>
49+
<button
50+
v-on:click="downloadBackUpExportEncryptedFile()"
51+
v-if="encryption.getEncryptionStatus() && !isDataLinkSupported"
52+
class="button"
53+
>
54+
{{ i18n.download_enc_backup }}
55+
</button>
3256
</div>
3357
<a-button-link href="import.html">{{ i18n.import_backup }}</a-button-link>
3458
<br />
3559
<!-- 3rd Party Backup Services -->
36-
<div v-show="!backupDisabled">
60+
<div v-show="!backupDisabled && isBackupServiceSupported">
3761
<div class="text">
3862
{{ i18n.storage_sync_info }}
3963
</div>
@@ -46,6 +70,7 @@
4670
</template>
4771
<script lang="ts">
4872
import Vue from "vue";
73+
import { isSafari } from "../../browser";
4974
5075
export default Vue.extend({
5176
data: function () {
@@ -73,6 +98,12 @@ export default Vue.extend({
7398
backupDisabled: function () {
7499
return this.$store.getters["menu/storageArea"];
75100
},
101+
isDataLinkSupported: function () {
102+
return !isSafari;
103+
},
104+
isBackupServiceSupported: function () {
105+
return !isSafari;
106+
},
76107
},
77108
methods: {
78109
showInfo(tab: string) {
@@ -123,6 +154,22 @@ export default Vue.extend({
123154
return;
124155
}
125156
},
157+
downloadBackUpOneLineOtpAuthFile() {
158+
const exportData = this.$store.state.accounts.exportData;
159+
const t = getOneLineOtpBackupFile(exportData);
160+
window.open(t);
161+
},
162+
downloadBackUpExportFile() {
163+
const exportData = this.$store.state.accounts.exportData;
164+
const t = getBackupFile(exportData);
165+
window.open(t);
166+
},
167+
downloadBackUpExportEncryptedFile() {
168+
const exportEncData = this.$store.state.accounts.exportEncData;
169+
const key = this.$store.state.accounts.key;
170+
const t = getBackupFile(exportEncData, key);
171+
window.open(t);
172+
},
126173
},
127174
});
128175

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/components/Popup/MainHeader.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import IconScan from "../../../svg/scan.svg";
8484
import IconPencil from "../../../svg/pencil.svg";
8585
import IconCheck from "../../../svg/check.svg";
8686
import IconPlus from "../../../svg/plus.svg";
87+
import { isFirefox } from "../../browser";
8788
8889
const computedPrototype = [
8990
mapState("style", ["style"]),
@@ -106,7 +107,7 @@ export default Vue.extend({
106107
},
107108
popOut() {
108109
let windowType;
109-
if (navigator.userAgent.indexOf("Firefox") !== -1) {
110+
if (isFirefox) {
110111
windowType = "detached_panel";
111112
} else {
112113
windowType = "panel";
@@ -152,7 +153,7 @@ export default Vue.extend({
152153
return;
153154
}
154155
// Request permissions
155-
if (navigator.userAgent.indexOf("Firefox") !== -1) {
156+
if (isFirefox) {
156157
await new Promise((resolve: (value: void) => void) => {
157158
chrome.permissions.request(
158159
{ origins: ["<all_urls>"] },

0 commit comments

Comments
 (0)