Skip to content

Commit

Permalink
settings: Save and restore selected application
Browse files Browse the repository at this point in the history
Closes #556
  • Loading branch information
tchx84 committed Sep 5, 2023
1 parent 9e148b0 commit 28eb72c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions data/com.github.tchx84.Flatseal.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
<key name="window-maximized" type="b">
<default>false</default>
</key>
<key name="selected-app-id" type="s">
<default>""</default>
<summary>Application ID that was last selected</summary>
</key>
</schema>
</schemalist>
8 changes: 8 additions & 0 deletions src/models/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ var FlatsealSettingsModel = GObject.registerClass({
}
this._settings.set_boolean('window-maximized', window.maximized);
}

getSelectedAppId() {
return this._settings.get_string('selected-app-id');
}

setSelectedAppId(appId) {
this._settings.set_string('selected-app-id', appId);
}
});
14 changes: 12 additions & 2 deletions src/widgets/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@ var FlatsealWindow = GObject.registerClass({
if (allApplications.length === 0 || allPermissions.length === 0)
return;

let selectedRow = null;
const iconTheme = Gtk.IconTheme.get_for_display(this.get_display());

allApplications.forEach(app => {
iconTheme.add_search_path(app.appThemePath);
const row = new FlatsealApplicationRow(app.appId, app.appName, app.appIconName);
this._applicationsListBox.append(row);

if (app.appId === this._settings.getSelectedAppId())
selectedRow = row;
});

/* Add row for global overrides */
Expand Down Expand Up @@ -222,8 +226,13 @@ var FlatsealWindow = GObject.registerClass({
this._applicationsListBox.set_sort_func(this._sort.bind(this));

/* select after the list has been sorted */
const row = this._applicationsListBox.get_row_at_index(1);
this._applicationsListBox.select_row(row);
if (selectedRow === null)
selectedRow = this._applicationsListBox.get_row_at_index(1);

/* XXX switch to ListBox.scroll_to when available */
selectedRow.grab_focus();

this._applicationsListBox.select_row(selectedRow);
this._updatePermissions();

this._applicationsDelayHandlerId = 0;
Expand Down Expand Up @@ -287,6 +296,7 @@ var FlatsealWindow = GObject.registerClass({
this._permissions.appId = row.appId;
this._permissionsTitle.title = row.appName;
this._updatePermissionsPane(row.appId);
this._settings.setSelectedAppId(row.appId);
this._toast.dismiss();

this._applicationsDelayHandlerId = 0;
Expand Down

0 comments on commit 28eb72c

Please sign in to comment.