Bug 1893277 - build initial UI for turning on scheduled backups. r=backup-reviewers,firefox-desktop-core-reviewers ,fluent-reviewers,mconley
backup-settings changes: - adds a new button in the Backup section of about:preferences / about:settings - shows the turn on dialog after pressing the button Turn on dialog behaviour (implemented): - pressing the cancel will close the dialog - pressing the confirm button will set the pref browser.backup.scheduled.enabled=true and close the dialog - pressing the passwords checkbox will show more options Turn on dialog behaviour (not implemented): - requiring a password for the backup (see Bug 1895981) - modifying the save location and showing a file picker (see Bug 1895943) Other changes: - tests for backup-settings and the turn on dialog - Storybook template for the turn on dialog Lo-fi Figma designs: https://www.figma.com/design/vNbX4c0ws0L1qr0mxpKvsW/Fx-Backup?node-id=147-4558&t=PYLY0QMN1n8GR9vW-0 Differential Revision: https://phabricator.services.mozilla.com/D209769
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
import * as DefaultBackupResources from "resource:///modules/backup/BackupResources.sys.mjs";
|
||||
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
|
||||
const SCHEDULED_BACKUPS_ENABLED_PREF_NAME = "browser.backup.scheduled.enabled";
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineLazyGetter(lazy, "logConsole", function () {
|
||||
@@ -33,6 +35,19 @@ ChromeUtils.defineLazyGetter(lazy, "ZipWriter", () =>
|
||||
Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter", "open")
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
lazy,
|
||||
"scheduledBackupsPref",
|
||||
SCHEDULED_BACKUPS_ENABLED_PREF_NAME,
|
||||
false,
|
||||
function onUpdateScheduledBackups(_pref, _prevVal, newVal) {
|
||||
let bs = BackupService.get();
|
||||
if (bs) {
|
||||
bs.onUpdateScheduledBackups(newVal);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* The BackupService class orchestrates the scheduling and creation of profile
|
||||
* backups. It also does most of the heavy lifting for the restoration of a
|
||||
@@ -94,7 +109,11 @@ export class BackupService extends EventTarget {
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
#_state = { backupInProgress: false };
|
||||
#_state = {
|
||||
backupFilePath: "Documents", // TODO: make save location configurable (bug 1895943)
|
||||
backupInProgress: false,
|
||||
scheduledBackupsEnabled: lazy.scheduledBackupsPref,
|
||||
};
|
||||
|
||||
/**
|
||||
* A Promise that will resolve once the postRecovery steps are done. It will
|
||||
@@ -844,6 +863,35 @@ export class BackupService extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets browser.backup.scheduled.enabled to true or false.
|
||||
*
|
||||
* @param { boolean } shouldEnableScheduledBackups true if scheduled backups should be enabled. Else, false.
|
||||
*/
|
||||
setScheduledBackups(shouldEnableScheduledBackups) {
|
||||
Services.prefs.setBoolPref(
|
||||
SCHEDULED_BACKUPS_ENABLED_PREF_NAME,
|
||||
shouldEnableScheduledBackups
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates scheduledBackupsEnabled in the backup service state. Should be called every time
|
||||
* the value for browser.backup.scheduled.enabled changes.
|
||||
*
|
||||
* @param {boolean} isScheduledBackupsEnabled True if scheduled backups are enabled. Else false.
|
||||
*/
|
||||
onUpdateScheduledBackups(isScheduledBackupsEnabled) {
|
||||
if (this.#_state.scheduledBackupsEnabled != isScheduledBackupsEnabled) {
|
||||
lazy.logConsole.debug(
|
||||
"Updating scheduled backups",
|
||||
isScheduledBackupsEnabled
|
||||
);
|
||||
this.#_state.scheduledBackupsEnabled = isScheduledBackupsEnabled;
|
||||
this.stateUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take measurements of the current profile state for Telemetry.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user