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:
@@ -2,9 +2,11 @@ import { FileBackupsDevice, FileBackupsMapping } from '@web/Application/Device/D
|
|||||||
import { AppState } from 'app/application'
|
import { AppState } from 'app/application'
|
||||||
import { shell } from 'electron'
|
import { shell } from 'electron'
|
||||||
import { StoreKeys } from '../Store'
|
import { StoreKeys } from '../Store'
|
||||||
|
import path from 'path'
|
||||||
import {
|
import {
|
||||||
|
deleteFile,
|
||||||
ensureDirectoryExists,
|
ensureDirectoryExists,
|
||||||
moveDirContents,
|
moveFiles,
|
||||||
openDirectoryPicker,
|
openDirectoryPicker,
|
||||||
readJSONFile,
|
readJSONFile,
|
||||||
writeFile,
|
writeFile,
|
||||||
@@ -61,12 +63,37 @@ export class FilesBackupManager implements FileBackupsDevice {
|
|||||||
const oldPath = await this.getFilesBackupsLocation()
|
const oldPath = await this.getFilesBackupsLocation()
|
||||||
|
|
||||||
if (oldPath) {
|
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)
|
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> {
|
public getFilesBackupsLocation(): Promise<string> {
|
||||||
|
|||||||
@@ -288,12 +288,13 @@ async function installComponent(
|
|||||||
const sendInstalledMessage = (component: Component, error?: { message: string; tag: string }) => {
|
const sendInstalledMessage = (component: Component, error?: { message: string; tag: string }) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
logError(`Error when installing component ${name}: ` + error.message)
|
logError(`Error when installing component ${name}: ` + error.message)
|
||||||
} else {
|
return
|
||||||
logMessage(`Installed component ${name} (${version})`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logMessage(`Installed component ${name} (${version})`)
|
||||||
|
|
||||||
webContents.send(MessageToWebApp.InstallComponentComplete, {
|
webContents.send(MessageToWebApp.InstallComponentComplete, {
|
||||||
component,
|
component,
|
||||||
error,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ function listenForMessagesSentFromMainToPreloadToUs(device: DesktopDevice) {
|
|||||||
} else if (message === MessageToWebApp.WindowFocused) {
|
} else if (message === MessageToWebApp.WindowFocused) {
|
||||||
receiver.windowGainedFocus()
|
receiver.windowGainedFocus()
|
||||||
} else if (message === MessageToWebApp.InstallComponentComplete) {
|
} else if (message === MessageToWebApp.InstallComponentComplete) {
|
||||||
receiver.onComponentInstallationComplete(data.component, data.error)
|
receiver.onComponentInstallationComplete(data.component, undefined)
|
||||||
} else if (message === MessageToWebApp.UpdateAvailable) {
|
} else if (message === MessageToWebApp.UpdateAvailable) {
|
||||||
receiver.updateAvailable()
|
receiver.updateAvailable()
|
||||||
} else if (message === MessageToWebApp.PerformAutomatedBackup) {
|
} else if (message === MessageToWebApp.PerformAutomatedBackup) {
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ export class DesktopManager
|
|||||||
return component.payloadRepresentation().ejected()
|
return component.payloadRepresentation().ejected()
|
||||||
}
|
}
|
||||||
|
|
||||||
// All `components` should be installed
|
|
||||||
syncComponentsInstallation(components: SNComponent[]) {
|
syncComponentsInstallation(components: SNComponent[]) {
|
||||||
Promise.all(
|
Promise.all(
|
||||||
components.map((component) => {
|
components.map((component) => {
|
||||||
@@ -114,7 +113,7 @@ export class DesktopManager
|
|||||||
this.webApplication.notifyWebEvent(WebAppEvent.WindowDidBlur)
|
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)
|
const component = this.application.items.findItem(componentData.uuid)
|
||||||
if (!component) {
|
if (!component) {
|
||||||
return
|
return
|
||||||
@@ -124,15 +123,11 @@ export class DesktopManager
|
|||||||
component,
|
component,
|
||||||
(m) => {
|
(m) => {
|
||||||
const mutator = m as ComponentMutator
|
const mutator = m as ComponentMutator
|
||||||
if (error) {
|
// eslint-disable-next-line camelcase
|
||||||
mutator.setAppDataItem(AppDataField.ComponentInstallError, error)
|
mutator.local_url = componentData.content.local_url as string
|
||||||
} else {
|
// eslint-disable-next-line camelcase
|
||||||
// eslint-disable-next-line camelcase
|
mutator.package_info = componentData.content.package_info
|
||||||
mutator.local_url = componentData.content.local_url as string
|
mutator.setAppDataItem(AppDataField.ComponentInstallError, undefined)
|
||||||
// eslint-disable-next-line camelcase
|
|
||||||
mutator.package_info = componentData.content.package_info
|
|
||||||
mutator.setAppDataItem(AppDataField.ComponentInstallError, undefined)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user