- Adds button in the preferences backup settings to restore from a backup file. - Adds a dialog component `restore-from-backup` which will open a filepicker to select a HTML backup file to restore from, show the backup's date and prompt to input a password if needed. - Adds a stub `getBackupInfo` event to eventually return metadata and config JSON from `sampleArchive` in Bug 1901132. Does not yet implement: - Expanding the input to fit multiline files names. - Restoring the selected backup file. Figma: https://www.figma.com/design/vNbX4c0ws0L1qr0mxpKvsW/Fx-Backup?node-id=147-8701&t=zvoykS3OusX9YVCv-4 Differential Revision: https://phabricator.services.mozilla.com/D211248
237 lines
7.3 KiB
JavaScript
237 lines
7.3 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
import { html } from "chrome://global/content/vendor/lit.all.mjs";
|
|
import { MozLitElement } from "chrome://global/content/lit-utils.mjs";
|
|
|
|
// eslint-disable-next-line import/no-unassigned-import
|
|
import "chrome://browser/content/backup/turn-on-scheduled-backups.mjs";
|
|
// eslint-disable-next-line import/no-unassigned-import
|
|
import "chrome://browser/content/backup/turn-off-scheduled-backups.mjs";
|
|
// eslint-disable-next-line import/no-unassigned-import
|
|
import "chrome://browser/content/backup/restore-from-backup.mjs";
|
|
|
|
/**
|
|
* The widget for managing the BackupService that is embedded within the main
|
|
* document of about:settings / about:preferences.
|
|
*/
|
|
export default class BackupSettings extends MozLitElement {
|
|
static properties = {
|
|
backupServiceState: { type: Object },
|
|
};
|
|
|
|
static get queries() {
|
|
return {
|
|
scheduledBackupsButtonEl: "#backup-toggle-scheduled-button",
|
|
turnOnScheduledBackupsDialogEl: "#turn-on-scheduled-backups-dialog",
|
|
turnOnScheduledBackupsEl: "turn-on-scheduled-backups",
|
|
turnOffScheduledBackupsEl: "turn-off-scheduled-backups",
|
|
turnOffScheduledBackupsDialogEl: "#turn-off-scheduled-backups-dialog",
|
|
restoreFromBackupEl: "restore-from-backup",
|
|
restoreFromBackupButtonEl: "#backup-toggle-restore-button",
|
|
restoreFromBackupDialogEl: "#restore-from-backup-dialog",
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a BackupPreferences instance and sets the initial default
|
|
* state.
|
|
*/
|
|
constructor() {
|
|
super();
|
|
this.backupServiceState = {
|
|
backupDirPath: "",
|
|
backupFileToRestore: null,
|
|
backupFileInfo: null,
|
|
backupInProgress: false,
|
|
defaultParent: {
|
|
fileName: "",
|
|
path: "",
|
|
iconURL: "",
|
|
},
|
|
scheduledBackupsEnabled: false,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Dispatches the BackupUI:InitWidget custom event upon being attached to the
|
|
* DOM, which registers with BackupUIChild for BackupService state updates.
|
|
*/
|
|
connectedCallback() {
|
|
super.connectedCallback();
|
|
this.dispatchEvent(
|
|
new CustomEvent("BackupUI:InitWidget", { bubbles: true })
|
|
);
|
|
|
|
this.addEventListener("turnOnScheduledBackups", this);
|
|
this.addEventListener("turnOffScheduledBackups", this);
|
|
this.addEventListener("dialogCancel", this);
|
|
this.addEventListener("restoreFromBackupConfirm", this);
|
|
this.addEventListener("restoreFromBackupChooseFile", this);
|
|
this.addEventListener("getBackupFileInfo", this);
|
|
}
|
|
|
|
handleEvent(event) {
|
|
switch (event.type) {
|
|
case "turnOnScheduledBackups":
|
|
this.turnOnScheduledBackupsDialogEl.close();
|
|
this.dispatchEvent(
|
|
new CustomEvent("BackupUI:ToggleScheduledBackups", {
|
|
bubbles: true,
|
|
composed: true,
|
|
detail: {
|
|
...event.detail,
|
|
isScheduledBackupsEnabled: true,
|
|
},
|
|
})
|
|
);
|
|
break;
|
|
case "turnOffScheduledBackups":
|
|
this.turnOffScheduledBackupsDialogEl.close();
|
|
this.dispatchEvent(
|
|
new CustomEvent("BackupUI:ToggleScheduledBackups", {
|
|
bubbles: true,
|
|
composed: true,
|
|
detail: {
|
|
isScheduledBackupsEnabled: false,
|
|
},
|
|
})
|
|
);
|
|
break;
|
|
case "dialogCancel":
|
|
if (this.turnOnScheduledBackupsDialogEl.open) {
|
|
this.turnOnScheduledBackupsDialogEl.close();
|
|
} else if (this.turnOffScheduledBackupsDialogEl.open) {
|
|
this.turnOffScheduledBackupsDialogEl.close();
|
|
} else if (this.restoreFromBackupDialogEl.open) {
|
|
this.restoreFromBackupDialogEl.close();
|
|
}
|
|
break;
|
|
case "restoreFromBackupConfirm":
|
|
this.restoreFromBackupDialogEl.close();
|
|
this.dispatchEvent(
|
|
new CustomEvent("BackupUI:RestoreFromBackupFile", {
|
|
bubbles: true,
|
|
composed: true,
|
|
detail: {
|
|
backupFile: event.detail.backupFile,
|
|
},
|
|
})
|
|
);
|
|
break;
|
|
case "restoreFromBackupChooseFile":
|
|
this.dispatchEvent(
|
|
new CustomEvent("BackupUI:RestoreFromBackupChooseFile", {
|
|
bubbles: true,
|
|
composed: true,
|
|
})
|
|
);
|
|
break;
|
|
case "getBackupFileInfo":
|
|
this.dispatchEvent(
|
|
new CustomEvent("BackupUI:GetBackupFileInfo", {
|
|
bubbles: true,
|
|
composed: true,
|
|
detail: {
|
|
backupFile: event.detail.backupFile,
|
|
backupPassword: event.detail.backupPassword,
|
|
},
|
|
})
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
handleShowScheduledBackups() {
|
|
if (
|
|
!this.backupServiceState.scheduledBackupsEnabled &&
|
|
this.turnOnScheduledBackupsDialogEl
|
|
) {
|
|
this.turnOnScheduledBackupsDialogEl.showModal();
|
|
} else if (
|
|
this.backupServiceState.scheduledBackupsEnabled &&
|
|
this.turnOffScheduledBackupsDialogEl
|
|
) {
|
|
this.turnOffScheduledBackupsDialogEl.showModal();
|
|
}
|
|
}
|
|
|
|
turnOnScheduledBackupsDialogTemplate() {
|
|
let { fileName, path, iconURL } = this.backupServiceState.defaultParent;
|
|
return html`<dialog id="turn-on-scheduled-backups-dialog">
|
|
<turn-on-scheduled-backups
|
|
defaultlabel=${fileName}
|
|
defaultpath=${path}
|
|
defaulticonurl=${iconURL}
|
|
></turn-on-scheduled-backups>
|
|
</dialog>`;
|
|
}
|
|
|
|
turnOffScheduledBackupsDialogTemplate() {
|
|
return html`<dialog id="turn-off-scheduled-backups-dialog">
|
|
<turn-off-scheduled-backups></turn-off-scheduled-backups>
|
|
</dialog>`;
|
|
}
|
|
|
|
restoreFromBackupDialogTemplate() {
|
|
let { backupFilePath, backupFileToRestore, backupFileInfo } =
|
|
this.backupServiceState;
|
|
return html`<dialog id="restore-from-backup-dialog">
|
|
<restore-from-backup
|
|
.backupFilePath=${backupFilePath}
|
|
.backupFileToRestore=${backupFileToRestore}
|
|
.backupFileInfo=${backupFileInfo}
|
|
></restore-from-backup>
|
|
</dialog>`;
|
|
}
|
|
|
|
restoreFromBackupTemplate() {
|
|
return html`<div id="restore-from-backup">
|
|
${this.restoreFromBackupDialogTemplate()}
|
|
|
|
<moz-button
|
|
id="backup-toggle-restore-button"
|
|
@click=${this.handleShowRestoreDialog}
|
|
data-l10n-id="settings-data-backup-restore-choose"
|
|
></moz-button>
|
|
</div>`;
|
|
}
|
|
|
|
handleShowRestoreDialog() {
|
|
if (this.restoreFromBackupDialogEl) {
|
|
this.restoreFromBackupDialogEl.showModal();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
return html`<link
|
|
rel="stylesheet"
|
|
href="chrome://browser/skin/preferences/preferences.css"
|
|
/>
|
|
<link
|
|
rel="stylesheet"
|
|
href="chrome://browser/content/backup/backup-settings.css"
|
|
/>
|
|
<div id="scheduled-backups">
|
|
<div>
|
|
Backup in progress:
|
|
${this.backupServiceState.backupInProgress ? "Yes" : "No"}
|
|
</div>
|
|
|
|
${this.turnOnScheduledBackupsDialogTemplate()}
|
|
${this.turnOffScheduledBackupsDialogTemplate()}
|
|
|
|
<moz-button
|
|
id="backup-toggle-scheduled-button"
|
|
@click=${this.handleShowScheduledBackups}
|
|
data-l10n-id="settings-data-backup-toggle"
|
|
></moz-button>
|
|
|
|
${this.restoreFromBackupTemplate()}
|
|
</div> `;
|
|
}
|
|
}
|
|
|
|
customElements.define("backup-settings", BackupSettings);
|