fix: export decrypted backup for desktop in some cases
Mainly, when a backup is requested and no protection sources are available.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
ApplicationService,
|
ApplicationService,
|
||||||
ApplicationEvent,
|
ApplicationEvent,
|
||||||
removeFromArray,
|
removeFromArray,
|
||||||
|
BackupFile,
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
@@ -14,33 +15,32 @@ import { WebApplication } from '@/ui_models/application';
|
|||||||
import { isDesktopApplication } from '@/utils';
|
import { isDesktopApplication } from '@/utils';
|
||||||
import { Bridge } from './bridge';
|
import { Bridge } from './bridge';
|
||||||
|
|
||||||
type UpdateObserverCallback = (component: SNComponent) => void
|
type UpdateObserverCallback = (component: SNComponent) => void;
|
||||||
type ComponentActivationCallback = (payload: PurePayload) => void
|
type ComponentActivationCallback = (payload: PurePayload) => void;
|
||||||
type ComponentActivationObserver = {
|
type ComponentActivationObserver = {
|
||||||
id: string;
|
id: string;
|
||||||
callback: ComponentActivationCallback;
|
callback: ComponentActivationCallback;
|
||||||
}
|
};
|
||||||
|
|
||||||
export class DesktopManager extends ApplicationService {
|
export class DesktopManager extends ApplicationService {
|
||||||
|
$rootScope: ng.IRootScopeService;
|
||||||
$rootScope: ng.IRootScopeService
|
$timeout: ng.ITimeoutService;
|
||||||
$timeout: ng.ITimeoutService
|
componentActivationObservers: ComponentActivationObserver[] = [];
|
||||||
componentActivationObservers: ComponentActivationObserver[] = []
|
|
||||||
updateObservers: {
|
updateObservers: {
|
||||||
callback: UpdateObserverCallback;
|
callback: UpdateObserverCallback;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
isDesktop = isDesktopApplication();
|
isDesktop = isDesktopApplication();
|
||||||
|
|
||||||
dataLoaded = false
|
dataLoaded = false;
|
||||||
lastSearchedText?: string
|
lastSearchedText?: string;
|
||||||
private removeComponentObserver?: () => void;
|
private removeComponentObserver?: () => void;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
$rootScope: ng.IRootScopeService,
|
$rootScope: ng.IRootScopeService,
|
||||||
$timeout: ng.ITimeoutService,
|
$timeout: ng.ITimeoutService,
|
||||||
application: WebApplication,
|
application: WebApplication,
|
||||||
private bridge: Bridge,
|
private bridge: Bridge
|
||||||
) {
|
) {
|
||||||
super(application);
|
super(application);
|
||||||
this.$rootScope = $rootScope;
|
this.$rootScope = $rootScope;
|
||||||
@@ -74,10 +74,7 @@ export class DesktopManager extends ApplicationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getExtServerHost() {
|
getExtServerHost() {
|
||||||
console.assert(
|
console.assert(!!this.bridge.extensionsServerHost, 'extServerHost is null');
|
||||||
!!this.bridge.extensionsServerHost,
|
|
||||||
'extServerHost is null'
|
|
||||||
);
|
|
||||||
return this.bridge.extensionsServerHost;
|
return this.bridge.extensionsServerHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +94,14 @@ export class DesktopManager extends ApplicationService {
|
|||||||
if (!this.isDesktop) {
|
if (!this.isDesktop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Promise.all(components.map((component) => {
|
Promise.all(
|
||||||
return this.convertComponentForTransmission(component);
|
components.map((component) => {
|
||||||
})).then((payloads) => {
|
return this.convertComponentForTransmission(component);
|
||||||
|
})
|
||||||
|
).then((payloads) => {
|
||||||
this.bridge.syncComponents(
|
this.bridge.syncComponents(
|
||||||
payloads.filter(payload =>
|
payloads.filter(
|
||||||
!payload.errorDecrypting && !payload.waitingForKey
|
(payload) => !payload.errorDecrypting && !payload.waitingForKey
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -110,7 +109,7 @@ export class DesktopManager extends ApplicationService {
|
|||||||
|
|
||||||
registerUpdateObserver(callback: UpdateObserverCallback) {
|
registerUpdateObserver(callback: UpdateObserverCallback) {
|
||||||
const observer = {
|
const observer = {
|
||||||
callback: callback
|
callback: callback,
|
||||||
};
|
};
|
||||||
this.updateObservers.push(observer);
|
this.updateObservers.push(observer);
|
||||||
return () => {
|
return () => {
|
||||||
@@ -153,19 +152,14 @@ export class DesktopManager extends ApplicationService {
|
|||||||
(m) => {
|
(m) => {
|
||||||
const mutator = m as ComponentMutator;
|
const mutator = m as ComponentMutator;
|
||||||
if (error) {
|
if (error) {
|
||||||
mutator.setAppDataItem(
|
mutator.setAppDataItem(AppDataField.ComponentInstallError, error);
|
||||||
AppDataField.ComponentInstallError,
|
|
||||||
error
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
mutator.local_url = componentData.content.local_url;
|
mutator.local_url = componentData.content.local_url;
|
||||||
mutator.package_info = componentData.content.package_info;
|
mutator.package_info = componentData.content.package_info;
|
||||||
mutator.setAppDataItem(
|
mutator.setAppDataItem(AppDataField.ComponentInstallError, undefined);
|
||||||
AppDataField.ComponentInstallError,
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
for (const observer of this.updateObservers) {
|
for (const observer of this.updateObservers) {
|
||||||
@@ -174,13 +168,17 @@ export class DesktopManager extends ApplicationService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop_registerComponentActivationObserver(callback: ComponentActivationCallback) {
|
desktop_registerComponentActivationObserver(
|
||||||
|
callback: ComponentActivationCallback
|
||||||
|
) {
|
||||||
const observer = { id: `${Math.random}`, callback: callback };
|
const observer = { id: `${Math.random}`, callback: callback };
|
||||||
this.componentActivationObservers.push(observer);
|
this.componentActivationObservers.push(observer);
|
||||||
return observer;
|
return observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop_deregisterComponentActivationObserver(observer: ComponentActivationObserver) {
|
desktop_deregisterComponentActivationObserver(
|
||||||
|
observer: ComponentActivationObserver
|
||||||
|
) {
|
||||||
removeFromArray(this.componentActivationObservers, observer);
|
removeFromArray(this.componentActivationObservers, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +196,9 @@ export class DesktopManager extends ApplicationService {
|
|||||||
|
|
||||||
async desktop_requestBackupFile() {
|
async desktop_requestBackupFile() {
|
||||||
const data = await this.application!.createBackupFile(
|
const data = await this.application!.createBackupFile(
|
||||||
EncryptionIntent.FileEncrypted
|
this.application.hasProtectionSources()
|
||||||
|
? EncryptionIntent.FileEncrypted
|
||||||
|
: EncryptionIntent.FileDecrypted
|
||||||
);
|
);
|
||||||
if (data) {
|
if (data) {
|
||||||
return JSON.stringify(data, null, 2);
|
return JSON.stringify(data, null, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user