Merge branch 'develop' into feature/privileges-simplification

This commit is contained in:
Baptiste Grob
2021-01-18 13:21:13 +01:00
9 changed files with 76 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
import { WebApplication } from '@/ui_models/application';
import { EncryptionIntent, ProtectedAction, SNItem, ContentType, SNNote } from '@standardnotes/snjs';
import { EncryptionIntent, ProtectedAction, SNItem, ContentType, SNNote, BackupFile } from '@standardnotes/snjs';
function zippableTxtName(name: string, suffix = ""): string {
const sanitizedName = name
@@ -22,22 +22,27 @@ export class ArchiveManager {
}
public async downloadBackup(encrypted: boolean) {
const items = this.application.allItems();
const run = async () => {
// download in Standard Notes format
const intent = encrypted
? EncryptionIntent.FileEncrypted
: EncryptionIntent.FileDecrypted;
const data = await this.application.createBackupFile(intent);
if (!data) {
return;
}
const blobData = new Blob(
[JSON.stringify(data, null, 2)],
{ type: 'text/json' }
);
if (encrypted) {
const data = await this.itemsData(items, intent);
this.downloadData(
data!,
blobData,
`Standard Notes Encrypted Backup and Import File - ${this.formattedDate()}.txt`
);
} else {
/** download as zipped plain text files */
this.downloadZippedItems(items);
this.downloadZippedDecryptedItems(data);
}
};
@@ -65,15 +70,6 @@ export class ArchiveManager {
return string;
}
private async itemsData(items: SNItem[], intent: EncryptionIntent) {
const data = await this.application.createBackupFile(items, intent);
if (!data) {
return undefined;
}
const blobData = new Blob([data], { type: 'text/json' });
return blobData;
}
private get zip() {
return (window as any).zip;
}
@@ -95,17 +91,19 @@ export class ArchiveManager {
});
}
private async downloadZippedItems(
items: SNItem[]
private async downloadZippedDecryptedItems(
data: BackupFile
) {
await this.loadZip();
const items = data.items;
this.zip.createWriter(
new this.zip.BlobWriter('application/zip'),
async (zipWriter: any) => {
const data = await this.application.createBackupFile(items, EncryptionIntent.FileDecrypted);
await new Promise((resolve) => {
const blob = new Blob([data!], { type: 'text/plain' });
const blob = new Blob(
[JSON.stringify(data, null, 2)],
{ type: 'text/plain' }
);
const fileName = zippableTxtName(
'Standard Notes Backup and Import File.txt'
);

View File

@@ -17,8 +17,8 @@ import { Bridge } from './bridge';
type UpdateObserverCallback = (component: SNComponent) => void
type ComponentActivationCallback = (payload: PurePayload) => void
type ComponentActivationObserver = {
id: string,
callback: ComponentActivationCallback
id: string;
callback: ComponentActivationCallback;
}
export class DesktopManager extends ApplicationService {
@@ -27,7 +27,7 @@ export class DesktopManager extends ApplicationService {
$timeout: ng.ITimeoutService
componentActivationObservers: ComponentActivationObserver[] = []
updateObservers: {
callback: UpdateObserverCallback
callback: UpdateObserverCallback;
}[] = [];
isDesktop = isDesktopApplication();
@@ -165,7 +165,7 @@ export class DesktopManager extends ApplicationService {
undefined
);
}
})
});
this.$timeout(() => {
for (const observer of this.updateObservers) {
@@ -196,12 +196,11 @@ export class DesktopManager extends ApplicationService {
});
}
desktop_requestBackupFile() {
return this.application!.createBackupFile(
undefined,
undefined,
true
);
async desktop_requestBackupFile() {
const data = this.application!.createBackupFile(EncryptionIntent.FileEncrypted);
if (data) {
return JSON.stringify(data, null, 2);
}
}
desktop_didBeginBackup() {

View File

@@ -1,4 +1,4 @@
import { SNLog } from '@standardnotes/snjs';
import { isNullOrUndefined, SNLog } from '@standardnotes/snjs';
import { isDesktopApplication, isDev } from '@/utils';
import { storage, StorageKey } from './localStorage';
import Bugsnag from '@bugsnag/js';
@@ -6,6 +6,7 @@ import Bugsnag from '@bugsnag/js';
declare const __VERSION__: string;
declare global {
interface Window {
// eslint-disable-next-line camelcase
_bugsnag_api_key?: string;
}
}
@@ -21,8 +22,15 @@ function redactFilePath(line: string): string {
}
export function startErrorReporting() {
const disableErrorReporting = storage.get(StorageKey.DisableErrorReporting);
if (
storage.get(StorageKey.DisableErrorReporting) ||
/**
* Error reporting used to be opt-out, but is now opt-in, so
* treat the absence of an error reporting preference as an indication
* to disable error reporting.
*/
isNullOrUndefined(disableErrorReporting) ||
disableErrorReporting ||
!window._bugsnag_api_key
) {
SNLog.onError = console.error;