-
Notifications
You must be signed in to change notification settings - Fork 822
/
Copy pathImport.vue
84 lines (81 loc) · 2.16 KB
/
Import.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<div id="import" class="theme-normal">
<div v-if="!shouldShowPassphrase">
<div class="import_tab">
<input
type="radio"
id="import_file_radio"
value="FileImport"
v-model="importType"
/>
<label for="import_file_radio">{{ i18n.import_backup_file }}</label>
<input
type="radio"
id="import_qr_radio"
value="QrImport"
v-model="importType"
/>
<label for="import_qr_radio">{{ i18n.import_backup_qr }}</label>
<input
type="radio"
id="import_code_radio"
value="TextImport"
v-model="importType"
/>
<label for="import_code_radio">{{ i18n.import_backup_code }}</label>
</div>
<div>
<p id="import_info">
{{ i18n.otp_backup_inform }}
<a href="https://otp.ee/otpbackup" target="_blank">{{
i18n.otp_backup_learn
}}</a>
</p>
</div>
<component v-bind:is="importType" />
</div>
<div v-if="shouldShowPassphrase" class="error_password">
{{ i18n.import_error_password }}
</div>
</div>
</template>
<script lang="ts">
import Vue from "vue";
import FileImport from "./Import/FileImport.vue";
import QrImport from "./Import/QrImport.vue";
import TextImport from "./Import/TextImport.vue";
export default Vue.extend({
data: function () {
const query = location.search ? location.search.substr(1) : "";
const importType = ["FileImport", "QrImport", "TextImport"].includes(query)
? query
: "FileImport";
return {
importType,
shouldShowPassphrase: shouldShowPassphrase(this.$entries),
};
},
components: {
FileImport,
QrImport,
TextImport,
},
mounted() {
chrome.runtime.onMessage.addListener((event) => {
if (event.action === "stopImport") {
this.shouldShowPassphrase = true;
}
// https://stackoverflow.com/a/56483156
return true;
});
},
});
function shouldShowPassphrase(entries: OTPEntryInterface[]) {
for (const entry of entries) {
if (!entry.secret) {
return true;
}
}
return false;
}
</script>