fix: desktop backups directory change (#1178)

* fix: only move backup related files when changing file backups location

* fix: remove presently recursive error handling for third party component installation
This commit is contained in:
Mo
2022-06-29 09:03:09 -05:00
committed by GitHub
parent a3a654f381
commit b8efd823ac
4 changed files with 41 additions and 18 deletions

View File

@@ -2,9 +2,11 @@ import { FileBackupsDevice, FileBackupsMapping } from '@web/Application/Device/D
import { AppState } from 'app/application'
import { shell } from 'electron'
import { StoreKeys } from '../Store'
import path from 'path'
import {
deleteFile,
ensureDirectoryExists,
moveDirContents,
moveFiles,
openDirectoryPicker,
readJSONFile,
writeFile,
@@ -61,12 +63,37 @@ export class FilesBackupManager implements FileBackupsDevice {
const oldPath = await this.getFilesBackupsLocation()
if (oldPath) {
await moveDirContents(oldPath, newPath)
await this.transferFilesBackupsToNewLocation(oldPath, newPath)
} else {
this.appState.store.set(StoreKeys.FileBackupsLocation, newPath)
}
return newPath
}
private async transferFilesBackupsToNewLocation(oldPath: string, newPath: string): Promise<void> {
const mapping = await this.getMappingFileFromDisk()
if (!mapping) {
return
}
const entries = Object.values(mapping.files)
const itemFolders = entries.map((entry) => path.join(oldPath, entry.relativePath))
await moveFiles(itemFolders, newPath)
for (const entry of entries) {
entry.absolutePath = path.join(newPath, entry.relativePath)
}
const oldMappingFileLocation = this.getMappingFileLocation()
this.appState.store.set(StoreKeys.FileBackupsLocation, newPath)
return newPath
const result = await this.saveFilesBackupsMappingFile(mapping)
if (result === 'success') {
await deleteFile(oldMappingFileLocation)
}
}
public getFilesBackupsLocation(): Promise<string> {

View File

@@ -288,12 +288,13 @@ async function installComponent(
const sendInstalledMessage = (component: Component, error?: { message: string; tag: string }) => {
if (error) {
logError(`Error when installing component ${name}: ` + error.message)
} else {
logMessage(`Installed component ${name} (${version})`)
return
}
logMessage(`Installed component ${name} (${version})`)
webContents.send(MessageToWebApp.InstallComponentComplete, {
component,
error,
})
}

View File

@@ -152,7 +152,7 @@ function listenForMessagesSentFromMainToPreloadToUs(device: DesktopDevice) {
} else if (message === MessageToWebApp.WindowFocused) {
receiver.windowGainedFocus()
} else if (message === MessageToWebApp.InstallComponentComplete) {
receiver.onComponentInstallationComplete(data.component, data.error)
receiver.onComponentInstallationComplete(data.component, undefined)
} else if (message === MessageToWebApp.UpdateAvailable) {
receiver.updateAvailable()
} else if (message === MessageToWebApp.PerformAutomatedBackup) {

View File

@@ -68,7 +68,6 @@ export class DesktopManager
return component.payloadRepresentation().ejected()
}
// All `components` should be installed
syncComponentsInstallation(components: SNComponent[]) {
Promise.all(
components.map((component) => {
@@ -114,7 +113,7 @@ export class DesktopManager
this.webApplication.notifyWebEvent(WebAppEvent.WindowDidBlur)
}
async onComponentInstallationComplete(componentData: DecryptedTransferPayload<ComponentContent>, error: unknown) {
async onComponentInstallationComplete(componentData: DecryptedTransferPayload<ComponentContent>) {
const component = this.application.items.findItem(componentData.uuid)
if (!component) {
return
@@ -124,15 +123,11 @@ export class DesktopManager
component,
(m) => {
const mutator = m as ComponentMutator
if (error) {
mutator.setAppDataItem(AppDataField.ComponentInstallError, error)
} else {
// eslint-disable-next-line camelcase
mutator.local_url = componentData.content.local_url as string
// eslint-disable-next-line camelcase
mutator.package_info = componentData.content.package_info
mutator.setAppDataItem(AppDataField.ComponentInstallError, undefined)
}
// eslint-disable-next-line camelcase
mutator.local_url = componentData.content.local_url as string
// eslint-disable-next-line camelcase
mutator.package_info = componentData.content.package_info
mutator.setAppDataItem(AppDataField.ComponentInstallError, undefined)
},
undefined,
)