Fix/auto-backup (#6176)

* disable on change

* fix bug and try catch backup

* remove delay
This commit is contained in:
Jack Kavanagh 2023-07-20 00:26:21 +02:00 committed by GitHub
parent bb638b5e94
commit e000001055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 16 deletions

View File

@ -1,4 +1,4 @@
import fs, { mkdir } from 'node:fs/promises';
import { mkdir, writeFile } from 'node:fs/promises';
import path from 'node:path';
import electron from 'electron';
@ -11,17 +11,22 @@ import { isGrpcRequest } from '../models/grpc-request';
import { isRequest } from '../models/request';
import { isWebSocketRequest } from '../models/websocket-request';
export async function exportAllWorkspaces() {
const projects = await models.project.all();
await Promise.all(projects.map(async project => {
const dataPath = process.env['INSOMNIA_DATA_PATH'] || electron.app.getPath('userData');
const versionPath = path.join(dataPath, 'backups', version);
await mkdir(versionPath, { recursive: true });
const fileName = path.join(versionPath, `${project.name}.insomnia.json`);
const workspaces = await models.workspace.findByParentId(project._id);
const docs = await Promise.all(workspaces.map(parentDoc => db.withDescendants(parentDoc)));
const requests = docs.flat().filter(doc => isRequest(doc) || isGrpcRequest(doc) || isWebSocketRequest(doc));
const stringifiedExport = await exportRequestsData(requests, true, 'json');
await fs.writeFile(fileName, stringifiedExport);
console.log('Exported project backup to:', fileName);
}));
try {
const projects = await models.project.all();
await Promise.all(projects.map(async project => {
const dataPath = process.env['INSOMNIA_DATA_PATH'] || electron.app.getPath('userData');
const versionPath = path.join(dataPath, 'backups', version);
await mkdir(versionPath, { recursive: true });
const fileName = path.join(versionPath, `${project.name}.insomnia.json`);
const workspaces = await models.workspace.findByParentId(project._id);
const docs = await Promise.all(workspaces.map(parentDoc => db.withDescendants(parentDoc)));
const requests = docs.flat().filter(doc => isRequest(doc) || isGrpcRequest(doc) || isWebSocketRequest(doc));
const stringifiedExport = await exportRequestsData(requests, true, 'json');
await writeFile(fileName, stringifiedExport);
console.log('Exported project backup to:', fileName);
}
));
} catch (err) {
console.log('Error exporting project backup:', err);
}
}

View File

@ -63,7 +63,6 @@ export const init = async () => {
console.log(`[updater] Downloaded ${releaseName}`);
_sendUpdateStatus('Performing backup...');
await exportAllWorkspaces();
await delay(1000 * 10); // Workaround early restart issues
_sendUpdateStatus('Updated (Restart Required)');
dialog.showMessageBox({

View File

@ -19,7 +19,7 @@ export const CheckForUpdatesButton: FC<Props> = ({ children, className }) => {
return (
<button
className={className ?? ''}
disabled={disabled}
disabled={disabled || status !== 'Check now'}
onClick={() => {
window.main.manualUpdateCheck();
// this is to prevent initiating update multiple times