Skip to content

Commit

Permalink
nassh: include all profiles all the time when backing up
Browse files Browse the repository at this point in the history
The current backup code will only backup profiles that are referenced
by existing connections.  If no connections reference a profile, we
end up omitting it from the backup.  If there are no connections at
all, then even the "default" profile isn't saved.

Lets change the logic to walk all the profiles directly instead of
looking for the list indirectly via existing connections.

Change-Id: I18eec07504f13435f79c9972d3cc511c68545d61
Reviewed-on: https://chromium-review.googlesource.com/822823
Reviewed-by: Brandon Gilmore <[email protected]>
Tested-by: Mike Frysinger <[email protected]>
  • Loading branch information
vapier committed Dec 13, 2017
1 parent a0dba72 commit d069b1a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
27 changes: 26 additions & 1 deletion hterm/js/hterm_preference_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,38 @@ lib.rtdep('lib.f', 'lib.Storage');
*/
hterm.PreferenceManager = function(profileId) {
lib.PreferenceManager.call(this, hterm.defaultStorage,
'/hterm/profiles/' + profileId);
hterm.PreferenceManager.prefix_ + profileId);
var defs = hterm.PreferenceManager.defaultPreferences;
Object.keys(defs).forEach(function(key) {
this.definePreference(key, defs[key][1]);
}.bind(this));
};

/**
* The storage key prefix to namespace the preferences.
*/
hterm.PreferenceManager.prefix_ = '/hterm/profiles/';

/**
* List all the defined profiles.
*
* @param {function(Array<string>)} callback Called with the list of profiles.
*/
hterm.PreferenceManager.listProfiles = function(callback) {
hterm.defaultStorage.getItems(null, (items) => {
const profiles = {};
for (let key of Object.keys(items)) {
if (key.startsWith(hterm.PreferenceManager.prefix_)) {
// Turn "/hterm/profiles/foo/bar/cow" to "foo/bar/cow".
const subKey = key.slice(hterm.PreferenceManager.prefix_.length);
// Turn "foo/bar/cow" into "foo".
profiles[subKey.split('/', 1)[0]] = true;
}
}
callback(Object.keys(profiles));
});
};

hterm.PreferenceManager.categories = {};
hterm.PreferenceManager.categories.Keyboard = 'Keyboard';
hterm.PreferenceManager.categories.Appearance = 'Appearance';
Expand Down
37 changes: 15 additions & 22 deletions nassh/js/nassh.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ nassh.exportPreferences = function(onComplete) {
var pendingReads = 0;
var rv = {};

var onReadStorage = function(terminalProfile, prefs) {
rv.hterm[terminalProfile] = prefs.exportAsJson();
var onReadStorage = function(profile, prefs) {
rv.hterm[profile] = prefs.exportAsJson();
if (--pendingReads < 1)
onComplete(rv);
};
Expand All @@ -123,29 +123,22 @@ nassh.exportPreferences = function(onComplete) {

var nasshPrefs = new nassh.PreferenceManager();
nasshPrefs.readStorage(function() {
// Export all the connection settings.
rv.nassh = nasshPrefs.exportAsJson();
rv.hterm = {};

var profileIds = nasshPrefs.get('profile-ids');
if (profileIds.length == 0) {
onComplete(rv);
return;
}

for (var i = 0; i < profileIds.length; i++) {
var nasshProfilePrefs = nasshPrefs.getChild('profile-ids', profileIds[i]);
var terminalProfile = nasshProfilePrefs.get('terminal-profile');
if (!terminalProfile)
terminalProfile = 'default';

if (!(terminalProfile in rv.hterm)) {
rv.hterm[terminalProfile] = null;

var prefs = new hterm.PreferenceManager(terminalProfile);
prefs.readStorage(onReadStorage.bind(null, terminalProfile, prefs));
// Save all the profiles.
rv.hterm = {};
hterm.PreferenceManager.listProfiles((profiles) => {
profiles.forEach((profile) => {
rv.hterm[profile] = null;
const prefs = new hterm.PreferenceManager(profile);
prefs.readStorage(onReadStorage.bind(null, profile, prefs));
pendingReads++;
}
}
});

if (profiles.length == 0)
onComplete(rv);
});
});
};

Expand Down

0 comments on commit d069b1a

Please sign in to comment.