Skip to content

Commit

Permalink
fix: don't restore patched prototypes when suspending
Browse files Browse the repository at this point in the history
Patched prototypes should only be restored in the disable() method of
the extension, since gnome enforces extension rebasing when disabling
them. Restoring protos in any other place may lead to infinite recursion
if a different extension is also patching the same function.

See https://gitlab.gnome.org/ewlsh/gjs-guide/-/issues/75
    https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7629
Fixes: #585
  • Loading branch information
flexagoon committed May 3, 2024
1 parent 8cb0e5f commit 7af3721
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/components/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const OverviewBlur = class OverviewBlur {
{ name: 'bms-animation-backgroundgroup' }
);
this.enabled = false;
this.proto_patched = false;
}

enable() {
Expand All @@ -48,9 +49,9 @@ export const OverviewBlur = class OverviewBlur {

// part for the workspace animation switch

// make sure not to do this part if the extension was enabled prior, as
// make sure not to do this part if the functions were patched prior, as
// the functions would call themselves and cause infinite recursion
if (!this.enabled) {
if (!this.proto_patched) {
// store original workspace switching methods for restoring them on
// disable()
this._original_PrepareSwitch = wac_proto._prepareWorkspaceSwitch;
Expand Down Expand Up @@ -113,6 +114,8 @@ export const OverviewBlur = class OverviewBlur {

Main.uiGroup.remove_child(outer_this.animation_background_group);
};

this.proto_patched = true;
}

this.enabled = true;
Expand Down Expand Up @@ -184,18 +187,19 @@ export const OverviewBlur = class OverviewBlur {
style => Main.uiGroup.remove_style_class_name(style)
);

// make sure to absolutely not do this if the component was not enabled
// prior, as this would cause infinite recursion
if (this.enabled) {
// restore original behavior
this.connections.disconnect_all();
this.enabled = false;
}

restore_patched_proto() {
if (this.proto_patched) {
if (this._original_PrepareSwitch)
wac_proto._prepareWorkspaceSwitch = this._original_PrepareSwitch;
if (this._original_FinishSwitch)
wac_proto._finishWorkspaceSwitch = this._original_FinishSwitch;
}

this.connections.disconnect_all();
this.enabled = false;
this.proto_patched = false;
}
}

_log(str) {
Expand Down
1 change: 1 addition & 0 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export default class BlurMyShell extends Extension {
// disable every component from user session mode
if (this._user_session_mode_enabled)
this._disable_user_session();
this._overview_blur.restore_patched_proto();

// disable lockscreen blur too
this._lockscreen_blur.disable();
Expand Down

0 comments on commit 7af3721

Please sign in to comment.