Files
notesnook/apps/mobile/app/components/dialogs/vault/index.js

917 lines
26 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
import Clipboard from "@react-native-clipboard/clipboard";
2022-08-29 16:19:17 +05:00
import React, { Component, createRef } from "react";
import { InteractionManager, View } from "react-native";
import Share from "react-native-share";
import { notesnook } from "../../../../e2e/test.ids";
2022-08-29 16:19:17 +05:00
import { db } from "../../../common/database";
import { editorController } from "../../../screens/editor/tiptap/utils";
import BiometricService from "../../../services/biometrics";
import { DDS } from "../../../services/device-detection";
2020-03-10 23:19:16 +05:00
import {
2020-11-02 20:45:56 +05:00
eSendEvent,
eSubscribeEvent,
2022-01-22 12:57:05 +05:00
eUnSubscribeEvent,
ToastEvent
} from "../../../services/event-manager";
import Navigation from "../../../services/navigation";
import SearchService from "../../../services/search";
2023-06-10 12:17:23 +05:00
import { convertNoteToText } from "../../../utils/note-to-text";
import { getElevationStyle } from "../../../utils/elevation";
2020-03-10 23:19:16 +05:00
import {
eClearEditor,
eCloseActionSheet,
2020-03-21 10:03:11 +05:00
eCloseVaultDialog,
2020-03-10 23:19:16 +05:00
eOnLoadNote,
eOpenVaultDialog
} from "../../../utils/events";
import { deleteItems } from "../../../utils/functions";
import { tabBarRef } from "../../../utils/global-refs";
import { sleep } from "../../../utils/time";
import BaseDialog from "../../dialog/base-dialog";
import DialogButtons from "../../dialog/dialog-buttons";
import DialogHeader from "../../dialog/dialog-header";
import { Toast } from "../../toast";
import { Button } from "../../ui/button";
import Input from "../../ui/input";
import Seperator from "../../ui/seperator";
import Paragraph from "../../ui/typography/paragraph";
2020-11-17 20:17:50 +05:00
let Keychain;
2020-03-03 15:37:48 +05:00
const passInputRef = createRef();
2020-03-10 23:19:16 +05:00
const confirmPassRef = createRef();
2020-11-25 11:46:44 +05:00
const changePassInputRef = createRef();
2020-01-17 21:05:38 +05:00
export class VaultDialog extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
2020-03-10 23:19:16 +05:00
wrongPassword: false,
2020-11-25 11:46:44 +05:00
loading: false,
2020-03-10 23:19:16 +05:00
note: {},
vault: false,
locked: true,
permanant: false,
goToEditor: false,
share: false,
passwordsDontMatch: false,
2020-03-14 12:13:00 +05:00
deleteNote: false,
2020-11-02 20:45:56 +05:00
focusIndex: null,
2020-11-17 20:17:50 +05:00
biometricUnlock: false,
isBiometryEnrolled: false,
2020-11-17 20:17:50 +05:00
isBiometryAvailable: false,
fingerprintAccess: false,
2020-11-25 11:46:44 +05:00
changePassword: false,
2020-12-20 13:04:05 +05:00
copyNote: false,
revokeFingerprintAccess: false,
title: "Unlock Note",
2021-02-16 16:11:10 +05:00
description: null,
2021-07-08 12:45:41 +05:00
clearVault: false,
deleteVault: false,
deleteAll: false
2020-01-17 21:05:38 +05:00
};
this.password = null;
2020-03-17 15:09:15 +05:00
this.confirmPassword = null;
2020-11-25 11:46:44 +05:00
this.newPassword = null;
2021-02-16 16:11:10 +05:00
(this.title = !this.state.novault
? "Create Vault"
2021-02-16 16:11:10 +05:00
: this.state.fingerprintAccess
? "Vault Fingerprint Unlock"
2021-02-16 16:11:10 +05:00
: this.state.revokeFingerprintAccess
? "Revoke Vault Fingerprint Unlock"
2021-02-16 16:11:10 +05:00
: this.state.changePassword
? "Change Vault Password"
2021-02-16 16:11:10 +05:00
: this.state.note.locked
? this.state.deleteNote
? "Delete note"
2021-02-16 16:11:10 +05:00
: this.state.share
? "Share note"
2021-02-16 16:11:10 +05:00
: this.state.copyNote
? "Copy note"
2021-02-16 16:11:10 +05:00
: this.state.goToEditor
? "Unlock note"
: "Unlock note"
: "Lock note"),
2021-02-16 16:11:10 +05:00
(this.description = !this.state.novault
? "Set a password to create vault"
2021-02-16 16:11:10 +05:00
: this.state.fingerprintAccess
? "Enter vault password to enable fingerprint unlocking."
2021-02-16 16:11:10 +05:00
: this.state.revokeFingerprintAccess
? "Disable vault fingerprint unlock "
2021-02-16 16:11:10 +05:00
: this.state.changePassword
? "Setup a new password for the vault."
2021-02-16 16:11:10 +05:00
: this.state.permanant
? "Enter password to remove note from vault."
2021-02-16 16:11:10 +05:00
: this.state.note.locked
? this.state.deleteNote
? "Unlock note to delete it. If biometrics are not working, you can enter device pin to unlock vault."
2021-02-16 16:11:10 +05:00
: this.state.share
? "Unlock note to share it. If biometrics are not working, you can enter device pin to unlock vault."
2021-02-16 16:11:10 +05:00
: this.state.copyNote
? "Unlock note to copy it. If biometrics are not working, you can enter device pin to unlock vault."
2021-02-16 16:11:10 +05:00
: this.state.goToEditor
? "Unlock note to open it in editor. If biometrics are not working, you can enter device pin to unlock vault."
: "Enter vault password to unlock note. If biometrics are not working, you can enter device pin to unlock vault."
: "Enter vault password to lock note. If biometrics are not working, you can enter device pin to lock note.");
2020-01-17 21:05:38 +05:00
}
2020-01-17 00:23:16 +05:00
2020-03-10 23:19:16 +05:00
componentDidMount() {
eSubscribeEvent(eOpenVaultDialog, this.open);
eSubscribeEvent(eCloseVaultDialog, this.close);
}
componentWillUnmount() {
eUnSubscribeEvent(eOpenVaultDialog, this.open);
eUnSubscribeEvent(eCloseVaultDialog, this.close);
}
2020-11-17 20:17:50 +05:00
/**
*
2022-02-28 23:25:18 +05:00
* @param {import('../../../services/event-manager').vaultType} data
2020-11-17 20:17:50 +05:00
*/
open = async (data) => {
2021-02-15 11:08:05 +05:00
if (!Keychain) {
Keychain = require("react-native-keychain");
2021-02-15 11:08:05 +05:00
}
2021-02-16 13:23:43 +05:00
let biometry = await BiometricService.isBiometryAvailable();
2020-11-17 20:17:50 +05:00
let available = false;
let fingerprint = await BiometricService.hasInternetCredentials("nn_vault");
2021-02-16 13:23:43 +05:00
if (biometry) {
2020-11-17 20:17:50 +05:00
available = true;
}
2020-01-17 21:05:38 +05:00
this.setState({
2020-11-17 20:17:50 +05:00
note: data.item,
novault: data.novault,
locked: data.locked,
permanant: data.permanant,
goToEditor: data.goToEditor,
share: data.share,
deleteNote: data.deleteNote,
copyNote: data.copyNote,
isBiometryAvailable: available,
biometricUnlock: fingerprint,
isBiometryEnrolled: fingerprint,
2020-11-17 20:17:50 +05:00
fingerprintAccess: data.fingerprintAccess,
2020-11-25 11:46:44 +05:00
changePassword: data.changePassword,
revokeFingerprintAccess: data.revokeFingerprintAccess,
2021-02-16 16:11:10 +05:00
title: data.title,
description: data.description,
2021-07-08 12:45:41 +05:00
clearVault: data.clearVault,
deleteVault: data.deleteVault
2020-01-17 21:05:38 +05:00
});
if (
fingerprint &&
data.novault &&
!data.fingerprintAccess &&
!data.revokeFingerprintAccess &&
2021-07-08 12:45:41 +05:00
!data.changePassword &&
!data.clearVault &&
!data.deleteVault
) {
2021-02-16 16:11:10 +05:00
await this._onPressFingerprintAuth(data.title, data.description);
} else {
this.setState({
visible: true
});
2020-11-17 20:17:50 +05:00
}
2020-01-17 21:05:38 +05:00
};
2020-03-03 15:33:33 +05:00
2020-03-10 23:19:16 +05:00
close = () => {
2020-11-25 11:46:44 +05:00
if (this.state.loading) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: this.state.title,
message: "Please wait and do not close the app.",
type: "success",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-11-25 11:46:44 +05:00
return;
}
2022-04-24 05:59:14 +05:00
2023-04-01 14:06:16 +05:00
Navigation.queueRoutesForUpdate();
2022-04-24 05:59:14 +05:00
2020-03-19 11:05:52 +05:00
this.password = null;
this.confirmPassword = null;
2022-03-23 12:23:51 +05:00
SearchService.updateAndSearch();
2020-03-02 13:52:09 +05:00
this.setState({
visible: false,
2020-03-10 23:19:16 +05:00
note: {},
locked: false,
permanant: false,
goToEditor: false,
share: false,
novault: false,
2020-03-14 12:13:00 +05:00
deleteNote: false,
passwordsDontMatch: false
2020-03-02 13:52:09 +05:00
});
2020-01-17 21:05:38 +05:00
};
onPress = async () => {
if (this.state.revokeFingerprintAccess) {
await this._revokeFingerprintAccess();
2021-06-07 11:53:27 +05:00
this.close();
return;
}
2020-11-25 11:46:44 +05:00
if (this.state.loading) return;
2020-12-20 13:04:05 +05:00
2020-11-25 12:09:07 +05:00
if (!this.password) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Password not entered",
message: "Enter a password for the vault and try again.",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-12-20 13:04:05 +05:00
return;
2020-11-25 12:09:07 +05:00
}
2020-12-20 13:04:05 +05:00
if (this.password && this.password.length < 3) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Password too short",
message: "Password must be longer than 3 characters.",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-03-14 12:59:52 +05:00
2020-12-20 13:04:05 +05:00
return;
}
if (!this.state.novault) {
2020-03-17 15:09:15 +05:00
if (this.password !== this.confirmPassword) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Passwords do not match",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-03-17 15:09:15 +05:00
this.setState({
passwordsDontMatch: true
2020-03-17 15:09:15 +05:00
});
2020-03-10 23:19:16 +05:00
return;
}
2020-03-17 15:09:15 +05:00
this._createVault();
2020-11-25 11:46:44 +05:00
} else if (this.state.changePassword) {
this.setState({
loading: true
2020-11-25 11:46:44 +05:00
});
db.vault
.changePassword(this.password, this.newPassword)
.then(() => {
2020-11-25 11:46:44 +05:00
this.setState({
loading: false
2020-11-25 11:46:44 +05:00
});
if (this.state.biometricUnlock) {
this._enrollFingerprint(this.newPassword);
}
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Vault password updated successfully",
type: "success",
context: "global"
2021-02-20 15:03:02 +05:00
});
2020-11-25 11:46:44 +05:00
this.close();
})
.catch((e) => {
2020-11-25 11:46:44 +05:00
this.setState({
loading: false
2020-11-25 11:46:44 +05:00
});
2020-11-25 12:10:25 +05:00
if (e.message === db.vault.ERRORS.wrongPassword) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Incorrect password",
message: "Please enter the correct password and try again",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-11-25 11:46:44 +05:00
}
});
2020-03-10 23:19:16 +05:00
} else if (this.state.locked) {
if (!this.password || this.password.trim() === 0) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Incorrect password",
message: "Please enter the correct password and try again",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-03-14 12:13:00 +05:00
this.setState({
wrongPassword: true
2020-03-14 12:13:00 +05:00
});
2020-03-03 15:44:31 +05:00
return;
2020-01-17 21:05:38 +05:00
}
if (this.state.note.locked) {
await this._unlockNote();
} else {
db.vault
.unlock(this.password)
.then(async () => {
this.setState({
wrongPassword: false
});
2020-12-20 13:04:05 +05:00
await this._lockNote();
})
.catch((e) => {
this._takeErrorAction(e);
});
}
} else if (this.state.fingerprintAccess) {
2020-11-25 11:46:44 +05:00
this._enrollFingerprint(this.password);
2021-07-08 12:45:41 +05:00
} else if (this.state.clearVault) {
await this.clearVault();
} else if (this.state.deleteVault) {
await this.deleteVault();
2020-03-10 23:19:16 +05:00
}
};
2021-07-08 12:45:41 +05:00
deleteVault = async () => {
this.setState({
loading: true
2021-07-08 12:45:41 +05:00
});
try {
let verified = await db.user.verifyPassword(this.password);
2022-04-01 00:57:55 +05:00
if (!(await db.user.getUser())) verified = true;
2021-07-08 12:45:41 +05:00
if (verified) {
await db.vault.delete(this.state.deleteAll);
eSendEvent("vaultUpdated");
2021-07-08 12:45:41 +05:00
this.setState({
loading: false
2021-07-08 12:45:41 +05:00
});
this.close();
} else {
ToastEvent.show({
heading: "Account password incorrect",
message: "Please enter correct password for your account.",
type: "error",
context: "local"
2021-07-08 12:45:41 +05:00
});
}
} catch (e) {
console.error(e);
}
2021-07-08 12:45:41 +05:00
this.setState({
loading: false
2021-07-08 12:45:41 +05:00
});
};
clearVault = async () => {
this.setState({
loading: true
2021-07-08 12:45:41 +05:00
});
try {
await db.vault.clear(this.password);
this.setState({
loading: false
2021-07-08 12:45:41 +05:00
});
this.close();
eSendEvent("vaultUpdated");
2021-07-08 12:45:41 +05:00
} catch (e) {
ToastEvent.show({
heading: "Vault password incorrect",
message: "Please enter correct password to clear vault.",
type: "error",
context: "local"
2021-07-08 12:45:41 +05:00
});
}
this.setState({
loading: false
2021-07-08 12:45:41 +05:00
});
};
2020-03-10 23:19:16 +05:00
async _lockNote() {
if (!this.password || this.password.trim() === 0) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Incorrect password",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-03-10 23:19:16 +05:00
return;
} else {
await db.vault.add(this.state.note.id);
if (this.state.note.id === editorController.current?.note?.id) {
eSendEvent(eClearEditor);
}
this.close();
2021-06-07 11:53:27 +05:00
ToastEvent.show({
message: "Note locked successfully",
type: "error",
context: "local"
2021-06-07 11:53:27 +05:00
});
this.setState({
loading: false
2020-03-10 23:19:16 +05:00
});
}
}
2020-03-03 15:33:33 +05:00
2020-03-10 23:19:16 +05:00
async _unlockNote() {
if (!this.password || this.password.trim() === 0) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Incorrect password",
message: "Please enter the correct password and try again",
type: "error",
context: "local"
2021-02-20 15:03:02 +05:00
});
2020-03-10 23:19:16 +05:00
return;
}
if (this.state.permanant) {
this._permanantUnlock();
2020-03-10 23:19:16 +05:00
} else {
await this._openNote();
2020-03-10 23:19:16 +05:00
}
}
2020-12-31 21:29:30 +05:00
_openNote = async () => {
try {
let note = await db.vault.open(this.state.note.id, this.password);
if (this.state.biometricUnlock && !this.state.isBiometryEnrolled) {
await this._enrollFingerprint(this.password);
}
if (this.state.goToEditor) {
this._openInEditor(note);
} else if (this.state.share) {
2020-12-31 21:33:14 +05:00
await this._shareNote(note);
2020-12-31 21:29:30 +05:00
} else if (this.state.deleteNote) {
await this._deleteNote();
} else if (this.state.copyNote) {
await this._copyNote(note);
2020-12-31 21:29:30 +05:00
}
} catch (e) {
console.log(e);
2020-12-31 21:29:30 +05:00
this._takeErrorAction(e);
}
};
2020-03-14 12:13:00 +05:00
async _deleteNote() {
2021-02-16 16:11:10 +05:00
try {
await db.vault.remove(this.state.note.id, this.password);
await deleteItems(this.state.note);
this.close();
} catch (e) {
this._takeErrorAction(e);
}
2020-03-10 23:19:16 +05:00
}
2020-11-25 11:46:44 +05:00
async _enrollFingerprint(password) {
2020-11-17 20:17:50 +05:00
try {
2021-01-01 15:37:47 +05:00
this.setState(
{
loading: true
2021-01-01 15:37:47 +05:00
},
async () => {
try {
await db.vault.unlock(password);
await BiometricService.storeCredentials(password);
this.setState({
loading: false
});
eSendEvent("vaultUpdated");
ToastEvent.show({
heading: "Biometric unlocking enabled!",
message: "Now you can unlock notes in vault with biometrics.",
type: "success",
context: "global"
});
this.close();
} catch (e) {
ToastEvent.show({
heading: "Incorrect password",
message:
"Please enter the correct vault password to enable biometrics.",
type: "error",
context: "local"
});
this.setState({
loading: false
});
return;
}
}
2021-01-01 15:37:47 +05:00
);
2020-11-17 20:17:50 +05:00
} catch (e) {
this._takeErrorAction(e);
}
}
2020-03-10 23:19:16 +05:00
async _createVault() {
await db.vault.create(this.password);
2021-02-16 13:23:43 +05:00
2020-11-17 20:17:50 +05:00
if (this.state.biometricUnlock) {
2021-02-16 13:23:43 +05:00
await this._enrollFingerprint(this.password);
2020-11-17 20:17:50 +05:00
}
2021-04-07 11:18:11 +05:00
if (this.state.note?.id) {
2020-03-10 23:19:16 +05:00
await db.vault.add(this.state.note.id);
if (this.state.note.id === editorController.current?.note?.id) {
eSendEvent(eClearEditor);
}
2021-02-16 13:23:43 +05:00
this.setState({
loading: false
2021-02-16 13:23:43 +05:00
});
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Note added to vault",
type: "success",
context: "global"
2021-02-20 15:03:02 +05:00
});
2021-02-16 13:23:43 +05:00
this.close();
2020-11-17 20:17:50 +05:00
} else {
eSendEvent("vaultUpdated");
2021-06-07 11:53:27 +05:00
ToastEvent.show({
heading: "Vault created successfully",
type: "success",
context: "global"
2021-06-07 11:53:27 +05:00
});
2020-11-17 20:17:50 +05:00
this.close();
2020-03-10 23:19:16 +05:00
}
}
_permanantUnlock() {
db.vault
.remove(this.state.note.id, this.password)
.then(() => {
2021-06-07 11:53:27 +05:00
ToastEvent.show({
heading: "Note permanantly unlocked.",
type: "success",
context: "global"
2021-06-07 11:53:27 +05:00
});
2020-03-10 23:19:16 +05:00
this.close();
})
.catch((e) => {
2020-03-10 23:19:16 +05:00
this._takeErrorAction(e);
});
}
_openInEditor(note) {
this.close();
2022-04-01 00:57:55 +05:00
InteractionManager.runAfterInteractions(async () => {
2020-12-31 21:33:14 +05:00
eSendEvent(eOnLoadNote, note);
if (!DDS.isTab) {
tabBarRef.current?.goToPage(1);
}
});
2020-03-10 23:19:16 +05:00
}
async _copyNote(note) {
2023-06-10 12:17:23 +05:00
Clipboard.setString(await convertNoteToText(note));
ToastEvent.show({
heading: "Note copied",
type: "success",
message: "Note has been copied to clipboard!",
context: "global"
2021-02-20 15:03:02 +05:00
});
2020-12-07 11:26:30 +05:00
this.close();
2020-12-01 16:36:19 +05:00
}
2020-12-31 21:33:14 +05:00
async _shareNote(note) {
this.close();
try {
await Share.open({
heading: "Share note",
2020-12-31 21:33:14 +05:00
failOnCancel: false,
2023-06-10 12:17:23 +05:00
message: await convertNoteToText(note)
2020-12-31 21:33:14 +05:00
});
} catch (e) {
console.error(e);
}
2020-03-10 23:19:16 +05:00
}
_takeErrorAction(e) {
if (
e.message === db.vault.ERRORS.wrongPassword ||
e.message === "FAILURE"
) {
2020-03-10 23:19:16 +05:00
this.setState({
wrongPassword: true,
visible: true
2020-03-10 23:19:16 +05:00
});
setTimeout(() => {
ToastEvent.show({
heading: "Incorrect password",
type: "error",
context: "local"
});
}, 500);
2020-03-10 23:19:16 +05:00
return;
}
2020-03-10 23:19:16 +05:00
}
2020-01-17 21:05:38 +05:00
_revokeFingerprintAccess = async () => {
try {
2021-02-16 13:23:43 +05:00
await BiometricService.resetCredentials();
eSendEvent("vaultUpdated");
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Biometric unlocking disabled!",
type: "success",
context: "global"
2021-02-20 15:03:02 +05:00
});
} catch (e) {
2021-02-20 15:03:02 +05:00
ToastEvent.show({
heading: "Failed to disable Biometric unlocking.",
2021-04-23 08:26:21 +05:00
message: e.message,
type: "success",
context: "global"
2021-02-20 15:03:02 +05:00
});
}
};
2021-02-16 16:11:10 +05:00
_onPressFingerprintAuth = async (title, description) => {
2020-11-17 20:17:50 +05:00
try {
2021-02-16 16:11:10 +05:00
let credentials = await BiometricService.getCredentials(
title || this.state.title,
description || this.state.description
2021-02-16 16:11:10 +05:00
);
2021-02-16 13:23:43 +05:00
2020-11-17 20:17:50 +05:00
if (credentials?.password) {
this.password = credentials.password;
this.onPress();
2021-02-16 13:23:43 +05:00
} else {
eSendEvent(eCloseActionSheet);
await sleep(300);
2021-02-16 13:23:43 +05:00
this.setState({
visible: true
2021-02-16 13:23:43 +05:00
});
2020-11-17 20:17:50 +05:00
}
} catch (e) {
console.error(e);
}
2020-11-17 20:17:50 +05:00
};
2020-01-17 21:05:38 +05:00
render() {
2022-01-22 12:57:05 +05:00
const { colors } = this.props;
2020-03-10 23:19:16 +05:00
const {
note,
visible,
novault,
2020-11-25 11:46:44 +05:00
deleteNote,
share,
goToEditor,
fingerprintAccess,
changePassword,
loading,
2021-07-08 12:45:41 +05:00
deleteVault,
clearVault
2020-03-10 23:19:16 +05:00
} = this.state;
2020-01-17 21:05:38 +05:00
2020-11-23 12:32:33 +05:00
if (!visible) return null;
2020-01-17 21:05:38 +05:00
return (
2020-09-27 13:05:26 +05:00
<BaseDialog
onShow={async () => {
2021-04-07 11:18:11 +05:00
await sleep(100);
2020-03-03 15:37:48 +05:00
passInputRef.current?.focus();
}}
2020-11-25 11:46:44 +05:00
statusBarTranslucent={false}
2020-09-27 13:05:26 +05:00
onRequestClose={this.close}
2022-01-22 12:57:05 +05:00
visible={true}
>
2019-12-07 08:41:48 +05:00
<View
style={{
2023-06-10 12:17:23 +05:00
...getElevationStyle(5),
width: DDS.isTab ? 350 : "85%",
borderRadius: 10,
global: implement the new theme engine (#2196) * mobile: theme * theme: add theme engine * mobile: migrate app colors to new theme engine * mobile: fixed some colors * mobile: fix colors * mobile: store theme info in store * theme: `ColorsType` -> `Variants` * theme: use explicit return type for `useThemeColors` * theme: add `backdrop` color * mobile: `const colors` -> `const {colors} * theme: add default pitch-black theme * mobile: manage theme state via theme-engine * mobile: add theme scopes * mobile: commit * mobile: fix button width on applock screen * mobile: fix typings * mobile: fix theme definition * web: add partial support for custom themes only context menus & popups are left. * theme: add dialog & sheet scopes * global: sync with master branch and make everything work again * mobile: fix theme-engine usage in editor & app * mobile: fix colors * mobile: fix colors * mobile: cleanup * mobile: fix status bar color incorrect on entering foreground * mobile: fix dark color scheme * web: move emotion theme provider to @notesnook/theme * editor: add support for theme enging * web: adjust hover & focus colors on list item * mobile: migrate share ext to theme engine * mobile: fix editor theme provider * clipper: add support for the new theme engine * mobile: fix statusbar color on switch from bg * misc: fix build * mobile: fix build * misc: fix colors * mobile: fix theme colors * mobile: fix bottom padding * server: add theme server * theme: add previewColors * server: support themes query pagination * mobile: add client from theme server * server: reset cache on sync repo * server: fix types * server: show ip & port on start server * server: theme updates * web: finalize new theme engine on web * editor: fix build * global: fix @emotion/react version to 11.11.1 * editor: update katex patch * web: fix imports * global: fix @trpc/* versions * global: a huge set of changes 1. get rid of ThemeVariant. All variants can now be accessed anywhere. 2. remove unnecessary button variants 3. make buttons more responsive 4. implement themes server * web: add support for theme search and theme switching * global: update lockfiles * mobile: fix error * theme: use vite-plugin-react to start theme server * web: add support for auto updating themes * mobile: update theme selector * mobile: update theme if new verison available * theme: add `isomorphic-fetch` package * global: update lockfiles * web: add theme details dialog * setup: add scope for themes server in bootstrap script * web: add production server url * web: update lockfile * web: update lockfile * mobile: remove `react-native-blob-util` * web: add support for endless scrolling in themes * web: bring back dark/light mode option in settings * web: fix colors in places * theme: add selected variant * global: use single typescript version across the projects * web: fix sort & group options not having submenus * web: apply selected variant where appropriate * ui: use unique id for all menu items * config: add ui scope for commits * theme: export button variant creation fn * web: fix only 1 theme showing in theme selector * web: fix navigation item hover & other colors * mobile: update theme * editor: fix toolbar group alignments * editor: set theme provider at app level * theme: use scope name to get current scope * mobile: fix color usage in message card * theme: remove caching * editor: bring back icons in table menus * theme: use zustand to manage theme engine state * web: fix login/signup theming * mobile: fix webpack build * misc: remove ThemeProvider usage * editor: adjust theming and styling of editor toolbar * mobile: refactor * editor: fix toolbar group padding everywhere * web: fix settings sidebar is not scrollable * web: add loading indicator for themes loading * mobile: fix warning * mobile: fix ui issues * web: fix Loader errors on build * theme: add getPreviewColors & validateTheme * theme: fix theme validation * mobile: load theme from file * mobile: fix share extension crash * mobile: rename state * theme: add sourceURL property * theme: refactor theme-engine * web: add support for loading theme from file * web: improve button hover interaction * mobile: fix floating button color * mobile: update theme * mobile: fix border radius of context menu * mobile: set sheet overlay color to theme backdrop * mobile: set sidemenu backdrop to theme backdrop --------- Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
2023-08-01 12:07:21 +05:00
backgroundColor: colors.primary.background,
paddingTop: 12
2022-01-22 12:57:05 +05:00
}}
>
2020-09-27 13:05:26 +05:00
<DialogHeader
2021-02-16 16:11:10 +05:00
title={this.state.title}
paragraph={this.state.description}
2020-09-27 13:05:26 +05:00
icon="shield"
padding={12}
2020-09-27 13:05:26 +05:00
/>
2021-07-28 11:57:44 +05:00
<Seperator half />
2020-09-27 13:05:26 +05:00
<View
style={{
paddingHorizontal: 12
2022-01-22 12:57:05 +05:00
}}
>
{(novault ||
changePassword ||
this.state.clearVault ||
this.state.deleteVault) &&
!this.state.revokeFingerprintAccess ? (
<>
<Input
fwdRef={passInputRef}
editable={!loading}
autoCapitalize="none"
testID={notesnook.ids.dialogs.vault.pwd}
onChangeText={(value) => {
this.password = value;
}}
marginBottom={
!this.state.biometricUnlock ||
!this.state.isBiometryEnrolled ||
!novault ||
changePassword
? 0
: 10
}
onSubmit={() => {
changePassword
? changePassInputRef.current?.focus()
: this.onPress;
}}
2022-02-28 13:48:59 +05:00
autoComplete="password"
returnKeyLabel={changePassword ? "Next" : this.state.title}
returnKeyType={changePassword ? "next" : "done"}
secureTextEntry
placeholder={changePassword ? "Current password" : "Password"}
/>
{!this.state.biometricUnlock ||
!this.state.isBiometryEnrolled ||
!novault ||
changePassword ? null : (
<Button
onPress={() =>
this._onPressFingerprintAuth("Unlock note", "")
}
icon="fingerprint"
width="100%"
title={"Biometric unlock"}
type="transparent"
/>
)}
</>
) : null}
{this.state.deleteVault && (
<Button
onPress={() =>
this.setState({
deleteAll: !this.state.deleteAll
})
2020-12-22 10:27:51 +05:00
}
icon={
this.state.deleteAll
? "check-circle-outline"
: "checkbox-blank-circle-outline"
}
style={{
marginTop: 10
}}
width="100%"
title={"Delete all notes"}
type="errorShade"
2020-11-17 20:17:50 +05:00
/>
)}
{changePassword ? (
<>
<Seperator half />
<Input
ref={changePassInputRef}
editable={!loading}
testID={notesnook.ids.dialogs.vault.changePwd}
autoCapitalize="none"
onChangeText={(value) => {
this.newPassword = value;
}}
2022-02-28 13:48:59 +05:00
autoComplete="password"
onSubmit={this.onPress}
returnKeyLabel="Change"
returnKeyType="done"
secureTextEntry
placeholder={"New password"}
/>
</>
) : null}
2020-11-25 11:46:44 +05:00
{!novault ? (
<View>
<Input
fwdRef={passInputRef}
autoCapitalize="none"
testID={notesnook.ids.dialogs.vault.pwd}
onChangeText={(value) => {
this.password = value;
}}
2022-02-28 13:48:59 +05:00
autoComplete="password"
returnKeyLabel="Next"
returnKeyType="next"
secureTextEntry
onSubmit={() => {
confirmPassRef.current?.focus();
}}
placeholder="Password"
2020-11-17 20:17:50 +05:00
/>
2020-09-09 11:10:35 +05:00
<Input
fwdRef={confirmPassRef}
autoCapitalize="none"
testID={notesnook.ids.dialogs.vault.pwdAlt}
secureTextEntry
validationType="confirmPassword"
customValidator={() => this.password}
errorMessage="Passwords do not match."
onErrorCheck={() => null}
marginBottom={0}
2022-02-28 13:48:59 +05:00
autoComplete="password"
returnKeyLabel="Create"
returnKeyType="done"
onChangeText={(value) => {
this.confirmPassword = value;
if (value !== this.password) {
this.setState({
passwordsDontMatch: true
});
} else {
this.setState({
passwordsDontMatch: false
});
}
}}
onSubmit={this.onPress}
placeholder="Confirm password"
/>
</View>
) : null}
2020-09-27 13:05:26 +05:00
{this.state.biometricUnlock &&
!this.state.isBiometryEnrolled &&
novault ? (
<Paragraph>
Unlock with password once to enable biometric access.
</Paragraph>
2021-09-13 08:53:16 +05:00
) : null}
{this.state.isBiometryAvailable &&
!this.state.fingerprintAccess &&
!this.state.clearVault &&
!this.state.deleteVault &&
((!this.state.biometricUnlock && !changePassword) || !novault) ? (
<Button
onPress={() => {
this.setState({
biometricUnlock: !this.state.biometricUnlock
});
}}
style={{
marginTop: 10
}}
icon="fingerprint"
width="100%"
title="Biometric unlocking"
global: implement the new theme engine (#2196) * mobile: theme * theme: add theme engine * mobile: migrate app colors to new theme engine * mobile: fixed some colors * mobile: fix colors * mobile: store theme info in store * theme: `ColorsType` -> `Variants` * theme: use explicit return type for `useThemeColors` * theme: add `backdrop` color * mobile: `const colors` -> `const {colors} * theme: add default pitch-black theme * mobile: manage theme state via theme-engine * mobile: add theme scopes * mobile: commit * mobile: fix button width on applock screen * mobile: fix typings * mobile: fix theme definition * web: add partial support for custom themes only context menus & popups are left. * theme: add dialog & sheet scopes * global: sync with master branch and make everything work again * mobile: fix theme-engine usage in editor & app * mobile: fix colors * mobile: fix colors * mobile: cleanup * mobile: fix status bar color incorrect on entering foreground * mobile: fix dark color scheme * web: move emotion theme provider to @notesnook/theme * editor: add support for theme enging * web: adjust hover & focus colors on list item * mobile: migrate share ext to theme engine * mobile: fix editor theme provider * clipper: add support for the new theme engine * mobile: fix statusbar color on switch from bg * misc: fix build * mobile: fix build * misc: fix colors * mobile: fix theme colors * mobile: fix bottom padding * server: add theme server * theme: add previewColors * server: support themes query pagination * mobile: add client from theme server * server: reset cache on sync repo * server: fix types * server: show ip & port on start server * server: theme updates * web: finalize new theme engine on web * editor: fix build * global: fix @emotion/react version to 11.11.1 * editor: update katex patch * web: fix imports * global: fix @trpc/* versions * global: a huge set of changes 1. get rid of ThemeVariant. All variants can now be accessed anywhere. 2. remove unnecessary button variants 3. make buttons more responsive 4. implement themes server * web: add support for theme search and theme switching * global: update lockfiles * mobile: fix error * theme: use vite-plugin-react to start theme server * web: add support for auto updating themes * mobile: update theme selector * mobile: update theme if new verison available * theme: add `isomorphic-fetch` package * global: update lockfiles * web: add theme details dialog * setup: add scope for themes server in bootstrap script * web: add production server url * web: update lockfile * web: update lockfile * mobile: remove `react-native-blob-util` * web: add support for endless scrolling in themes * web: bring back dark/light mode option in settings * web: fix colors in places * theme: add selected variant * global: use single typescript version across the projects * web: fix sort & group options not having submenus * web: apply selected variant where appropriate * ui: use unique id for all menu items * config: add ui scope for commits * theme: export button variant creation fn * web: fix only 1 theme showing in theme selector * web: fix navigation item hover & other colors * mobile: update theme * editor: fix toolbar group alignments * editor: set theme provider at app level * theme: use scope name to get current scope * mobile: fix color usage in message card * theme: remove caching * editor: bring back icons in table menus * theme: use zustand to manage theme engine state * web: fix login/signup theming * mobile: fix webpack build * misc: remove ThemeProvider usage * editor: adjust theming and styling of editor toolbar * mobile: refactor * editor: fix toolbar group padding everywhere * web: fix settings sidebar is not scrollable * web: add loading indicator for themes loading * mobile: fix warning * mobile: fix ui issues * web: fix Loader errors on build * theme: add getPreviewColors & validateTheme * theme: fix theme validation * mobile: load theme from file * mobile: fix share extension crash * mobile: rename state * theme: add sourceURL property * theme: refactor theme-engine * web: add support for loading theme from file * web: improve button hover interaction * mobile: fix floating button color * mobile: update theme * mobile: fix border radius of context menu * mobile: set sheet overlay color to theme backdrop * mobile: set sidemenu backdrop to theme backdrop --------- Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
2023-08-01 12:07:21 +05:00
iconColor={
this.state.biometricUnlock
? colors.selected.icon
: colors.primary.icon
}
type={this.state.biometricUnlock ? "transparent" : "selected"}
/>
) : null}
</View>
2020-11-17 20:17:50 +05:00
2020-09-27 13:05:26 +05:00
<DialogButtons
onPressNegative={this.close}
onPressPositive={this.onPress}
2020-11-25 11:46:44 +05:00
loading={loading}
positiveType={
deleteVault || clearVault ? "errorShade" : "transparent"
}
2020-09-27 13:05:26 +05:00
positiveTitle={
2021-07-08 12:45:41 +05:00
deleteVault
? "Delete"
2021-07-08 12:45:41 +05:00
: clearVault
? "Clear"
2021-07-08 12:45:41 +05:00
: fingerprintAccess
? "Enable"
: this.state.revokeFingerprintAccess
? "Revoke"
2020-11-25 11:46:44 +05:00
: changePassword
? "Change"
2020-11-17 20:17:50 +05:00
: note.locked
2020-11-25 11:46:44 +05:00
? deleteNote
? "Delete"
2020-11-25 11:46:44 +05:00
: share
? "Share "
2020-11-25 11:46:44 +05:00
: goToEditor
? "Open"
: "Unlock"
2020-11-17 20:17:50 +05:00
: !note.id
? "Create"
: "Lock"
2020-09-27 13:05:26 +05:00
}
/>
2019-12-07 08:41:48 +05:00
</View>
<Toast context="local" />
2020-09-27 13:05:26 +05:00
</BaseDialog>
2020-01-17 21:05:38 +05:00
);
}
}