fix: fix remove password show errors

pull/3178/head
Audric Ackermann 8 months ago
parent 996db72f96
commit 6068b63afc
No known key found for this signature in database

@ -64,7 +64,11 @@ window.setPassword = async (passPhrase, oldPhrase) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
ipc.once('set-password-response', (_event, response) => { ipc.once('set-password-response', (_event, response) => {
if (!response) { if (!response) {
return reject('window.setPassword: No response from main process'); // We don't reject here, but return undefined and handle the result in the caller.
// The reason is because we sometimes want to reject, but sometimes not depending on what the caller is doing (set/change/remove)
// For instance, removing a password makes `!response` true, and so we would reject here even if we
// technically didn't have an reason to.
return resolve(undefined);
} }
return resolve(response); return resolve(response);
}); });

@ -195,6 +195,9 @@ export class SessionSetPasswordDialog extends Component<Props, State> {
} }
try { try {
const updatedHash = await window.setPassword(enteredPassword, null); const updatedHash = await window.setPassword(enteredPassword, null);
if (!updatedHash) {
throw new Error('window.setPassword expected updatedHash to be set for actionSet');
}
await Storage.put('passHash', updatedHash); await Storage.put('passHash', updatedHash);
ToastUtils.pushToastSuccess( ToastUtils.pushToastSuccess(
@ -245,6 +248,9 @@ export class SessionSetPasswordDialog extends Component<Props, State> {
try { try {
const updatedHash = await window.setPassword(newPassword, oldPassword); const updatedHash = await window.setPassword(newPassword, oldPassword);
if (!updatedHash) {
throw new Error('window.setPassword expected updatedHash to be set for actionChange');
}
await Storage.put('passHash', updatedHash); await Storage.put('passHash', updatedHash);
ToastUtils.pushToastSuccess( ToastUtils.pushToastSuccess(
@ -276,7 +282,10 @@ export class SessionSetPasswordDialog extends Component<Props, State> {
} }
try { try {
await window.setPassword(null, oldPassword); const updatedHash = await window.setPassword(null, oldPassword);
if (updatedHash) {
throw new Error('window.setPassword expected updatedHash to be unset for actionRemove');
}
await Storage.remove('passHash'); await Storage.remove('passHash');
ToastUtils.pushToastWarning( ToastUtils.pushToastWarning(

@ -116,7 +116,7 @@ export abstract class PersistedJob<T extends PersistedJobData> {
}) })
.catch(e => { .catch(e => {
window.log.warn( window.log.warn(
'runJob() threw. this cannot happen, but rehtrowing as this should be handled in each jobs run()', 'runJob() threw. this cannot happen, but rethrowing as this should be handled in each jobs run()',
e e
); );
throw e; throw e;

2
ts/window.d.ts vendored

@ -47,7 +47,7 @@ declare global {
persistStore?: Persistor; persistStore?: Persistor;
restart: () => void; restart: () => void;
getSeedNodeList: () => Array<string> | undefined; getSeedNodeList: () => Array<string> | undefined;
setPassword: (newPassword: string | null, oldPassword: string | null) => Promise<string>; setPassword: (newPassword: string | null, oldPassword: string | null) => Promise<string | undefined>;
isOnline: boolean; isOnline: boolean;
toggleMediaPermissions: () => Promise<void>; toggleMediaPermissions: () => Promise<void>;
toggleCallMediaPermissionsTo: (enabled: boolean) => Promise<void>; toggleCallMediaPermissionsTo: (enabled: boolean) => Promise<void>;

Loading…
Cancel
Save