Skip to content

Commit

Permalink
Enable "Do Not Disturb" when active (gicmo#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmattrick committed Jan 20, 2022
1 parent 345dc61 commit f18bcd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data/settings.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<summary>Always show the icon</summary>
<description>Display the icon even if GameMode is currently not active.</description>
</key>
<key type="b" name="do-not-disturb">
<default>false</default>
<summary>Do Not Disturb</summary>
<description>Disable notification banners when GameMode is active.</description>
</key>
<key type="b" name="active-tint">
<default>false</default>
<summary>Active icon tint</summary>
Expand Down
19 changes: 19 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ var GameModeIndicator = GObject.registerClass(
super._init(0.0, 'GameMode');
this._settings = ExtensionUtils.getSettings();

this._gio_settings = new Gio.Settings({
schema_id: 'org.gnome.desktop.notifications',
});

/* Store the mode that needs to be returned to when gamemode exits */
this._return_dnd_mode = false;

this.connect('destroy', this._onDestroy.bind(this));

let box = new St.BoxLayout({style_class: 'panel-status-menu-box'});
Expand Down Expand Up @@ -182,6 +189,9 @@ var GameModeIndicator = GObject.registerClass(
this._signals = [];

this._client.close();

this._gio_settings.run_dispose();
this._gio_settings = null;
}

_ensureSource() {
Expand Down Expand Up @@ -253,6 +263,15 @@ var GameModeIndicator = GObject.registerClass(
/* update the icon */
this._sync();

if (this._settings.get_boolean('do-not-disturb')) {
if (is_on) {
this._return_dnd_mode = this._gio_settings.get_boolean("show-banners");
this._gio_settings.set_boolean("show-banners", false);
} else {
this._gio_settings.set_boolean("show-banners", this._return_dnd_mode);
}
}

if (this._settings.get_boolean('emit-notifications')) {
let status = getStatusText(is_on);
if (is_on)
Expand Down
2 changes: 2 additions & 0 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var GameModeSettings = GObject.registerClass(class GameModePrefWidget extends Gt
this.margin = 24;
this.add(this.make_row_switch('emit-notifications'));
this.add(this.make_row_switch('always-show-icon'));
this.add(this.make_row_switch('do-not-disturb'));
this.add(this.make_row_switch('active-tint', 'active-color'));
} else {
this.margin_start = 24;
Expand All @@ -31,6 +32,7 @@ var GameModeSettings = GObject.registerClass(class GameModePrefWidget extends Gt
this.margin_bottom = 24;
this.append(this.make_row_switch('emit-notifications'));
this.append(this.make_row_switch('always-show-icon'));
this.append(this.make_row_switch('do-not-disturb'));
this.append(this.make_row_switch('active-tint', 'active-color'));
}
}
Expand Down

0 comments on commit f18bcd5

Please sign in to comment.