Skip to content

Commit

Permalink
Implement confirm dialogs for suspend then hibernate and hybrid sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
slaclau committed Mar 28, 2024
1 parent d56e571 commit 4b20027
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 11 deletions.
76 changes: 69 additions & 7 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export default class HibernateButtonExtension extends Extension {
this._haveSuspendThenHibernate && !Main.sessionMode.isLocked && this._setting.get_boolean('show-suspend-then-hibernate');
}

_updateCustomReboot() {
this._customRestartMenuItem.visible =
!Main.sessionMode.isLocked && this._setting.get_boolean('show-custom-reboot');
}

_updateDefaults() {
console.log("Update defaults");
let menuItems = this.systemMenu._systemItem.menu._getMenuItems()
Expand All @@ -241,7 +246,7 @@ export default class HibernateButtonExtension extends Extension {
this.systemMenu._systemItem.menu.itemActivated();

if (this._setting.get_boolean('show-hibernate-dialog')) {
let HibernateDialogContent = {
let DialogContent = {
subject: C_('title', __('Hibernate')),
description: __('Do you really want to hibernate the system?'),
confirmButtons: [
Expand All @@ -251,17 +256,17 @@ export default class HibernateButtonExtension extends Extension {
key: Clutter.Escape,
},
{
signal: 'ConfirmedHibernate',
signal: 'Confirmed',
label: C_('button', __('Hibernate')),
default: true,
},
],
};

this._dialog = new ConfirmDialog(
HibernateDialogContent
DialogContent
);
this._dialog.connect('ConfirmedHibernate', () =>
this._dialog.connect('Confirmed', () =>
this._loginManagerHibernate()
);
this._dialog.open();
Expand All @@ -272,12 +277,68 @@ export default class HibernateButtonExtension extends Extension {

_onHybridSleepClicked() {
this.systemMenu._systemItem.menu.itemActivated();
this._loginManagerHybridSleep();

if (this._setting.get_boolean('show-hybrid-sleep-dialog')) {
let DialogContent = {
subject: C_('title', __('Hybrid Sleep')),
description: __('Do you really want to hybrid sleep the system?'),
confirmButtons: [
{
signal: 'Cancel',
label: C_('button', __('Cancel')),
key: Clutter.Escape,
},
{
signal: 'Confirmed',
label: C_('button', __('Hybrid Sleep')),
default: true,
},
],
};

this._dialog = new ConfirmDialog(
DialogContent
);
this._dialog.connect('Confirmed', () =>
this._loginManagerHybridSleep()
);
this._dialog.open();
} else {
this._loginManagerHybridSleep()
}
}

_onSuspendThenHibernateClicked() {
this.systemMenu._systemItem.menu.itemActivated();
this._loginManagerSuspendThenHibernate();

if (this._setting.get_boolean('show-suspend-then-hibernate-dialog')) {
let DialogContent = {
subject: C_('title', __('Suspend then Hibernate')),
description: __('Do you really want to suspend then hibernate the system?'),
confirmButtons: [
{
signal: 'Cancel',
label: C_('button', __('Cancel')),
key: Clutter.Escape,
},
{
signal: 'Confirmed',
label: C_('button', __('Suspend then Hibernate')),
default: true,
},
],
};

this._dialog = new ConfirmDialog(
DialogContent
);
this._dialog.connect('Confirmed', () =>
this._loginManagerSuspendThenHibernate()
);
this._dialog.open();
} else {
this._loginManagerSuspendThenHibernate()
}
}

_disableExtension() {
Expand Down Expand Up @@ -428,6 +489,7 @@ export default class HibernateButtonExtension extends Extension {
this._updateHaveHibernate();
this._updateHaveHybridSleep();
this._updateHaveSuspendThenHibernate();
this._updateCustomReboot();
}
);
}
Expand Down Expand Up @@ -519,7 +581,7 @@ export default class HibernateButtonExtension extends Extension {
var ConfirmDialog = GObject.registerClass(
{
Signals: {
ConfirmedHibernate: {param_types: [GObject.TYPE_BOOLEAN]},
Confirmed: {param_types: [GObject.TYPE_BOOLEAN]},
DisableExtension: {param_types: [GObject.TYPE_BOOLEAN]},
Cancel: {param_types: [GObject.TYPE_BOOLEAN]},
},
Expand Down
12 changes: 8 additions & 4 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ export default class Prefs extends ExtensionPreferences {
title: __('Restart...'),
});
modes_group.add(restart_row);
const restart_to_row = new Adw.SwitchRow({
title: __('Restart to...'),
});
modes_group.add(restart_to_row);
const shutdown_row = new Adw.SwitchRow({
title: __('Shutdown...'),
title: __('Power Off...'),
});
modes_group.add(shutdown_row);

Expand All @@ -136,12 +140,10 @@ export default class Prefs extends ExtensionPreferences {
dialog_group.add(hibernate_dialog_row);
const hybrid_dialog_row = new Adw.SwitchRow({
title: __('Hybrid sleep'),
subtitle: __('Not implemented yet'),
});
dialog_group.add(hybrid_dialog_row);
const suspend_then_hibernate_dialog_row = new Adw.SwitchRow({
title: __('Suspend then hibernate'),
subtitle: __('Not implemented yet'),
title: __('Suspend then Hibernate'),
});
dialog_group.add(suspend_then_hibernate_dialog_row);

Expand All @@ -156,6 +158,8 @@ export default class Prefs extends ExtensionPreferences {
Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('show-restart', restart_row, 'active',
Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('show-custom-reboot', restart_to_row, 'active',
Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('show-shutdown', shutdown_row, 'active',
Gio.SettingsBindFlags.DEFAULT);
window._settings.bind('show-hibernate-dialog', hibernate_dialog_row, 'active',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<key type="b" name="show-shutdown">
<default>true</default>
</key>
<key type="b" name="show-custom-reboot">
<default>true</default>
</key>
<key type="b" name="show-hibernate-dialog">
<default>true</default>
</key>
Expand Down

0 comments on commit 4b20027

Please sign in to comment.