Skip to content

Commit

Permalink
Fixes #80 - Support multiple databases being configured
Browse files Browse the repository at this point in the history
  • Loading branch information
palant committed Apr 29, 2023
1 parent 4f13fd6 commit 5acb0a3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions locale/en_US/components/EnterMainPassword.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"database_label": "Database:",
"password_label": "Enter main password:",
"submit": "Access passwords",
"password_required": "Please enter a main password.",
Expand Down
5 changes: 5 additions & 0 deletions ui/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ a.iconic-link:hover
outline: 1px solid #888;
}

#database
{
margin-bottom: var(--block-spacing);
}

.password-value-container
{
display: flex;
Expand Down
33 changes: 32 additions & 1 deletion ui/components/EnterMainPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

<template>
<ValidatedForm @validated="submit">
<template v-if="databases.length >= 2">
<label for="database">{{ $t("database_label") }}</label>
<select id="database" v-model="database">
<option v-for="name in databases" :key="name">{{ name }}</option>
</select>
</template>
<label for="main-password">{{ $t("password_label") }}</label>
<PasswordInput
id="main-password" v-model="password"
Expand All @@ -28,8 +34,9 @@
<script>
"use strict";
import {handleErrors} from "../common.js";
import {rememberKeys} from "../keys.js";
import {nativeRequest} from "../protocol.js";
import {nativeRequest, getDatabase, setDatabase} from "../protocol.js";
export default {
name: "EnterMainPassword",
Expand All @@ -38,17 +45,41 @@ export default {
data()
{
return {
database: null,
databases: [],
password: "",
passwordError: null,
inProgress: false
};
},
mounted: handleErrors(async function()
{
let [database, {databases, defaultDatabase}] = await Promise.all([
getDatabase(),
nativeRequest("get-databases", null)
]);
this.databases = databases.sort((a, b) =>
{
a = a.toLowerCase();
b = b.toLowerCase();
if (a < b)
return -1;
else if (a > b)
return 1;
else
return 0;
});
this.database = databases.includes(database) ? database : defaultDatabase;
}),
methods: {
async submit()
{
this.inProgress = true;
try
{
await setDatabase(this.database);
let keys = await nativeRequest("unlock", {
password: this.password
});
Expand Down
14 changes: 14 additions & 0 deletions ui/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"use strict";

import browser from "./browserAPI.js";
import {getPref, setPref} from "./prefs.js";

export const PROTOCOL_VERSION = "1.1";

Expand Down Expand Up @@ -58,9 +59,12 @@ export async function nativeRequest(action, request)
if (!port)
connect();

let database = await getDatabase();

let requestId = Math.random().toString().slice(2);
let message = {
requestId,
database,
action,
request
};
Expand All @@ -72,3 +76,13 @@ export async function nativeRequest(action, request)
responseQueue.set(requestId, [resolve, reject]);
});
}

export async function getDatabase()
{
return await getPref("database", null);
}

export async function setDatabase(database)
{
await setPref("database", database);
}

0 comments on commit 5acb0a3

Please sign in to comment.