Skip to content

Commit

Permalink
DockManager: Keep a fm1Client reference and destroy it when unneeded
Browse files Browse the repository at this point in the history
Instead of keeping the FileManager1 proxy around all the times, only create it
when needed and destroy it on extension destruction.
  • Loading branch information
3v1n0 committed Aug 19, 2019
1 parent 921b68d commit 6bddbc3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
18 changes: 10 additions & 8 deletions appIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const Workspace = imports.ui.workspace;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const Docking = Me.imports.docking;
const FileManager1API = Me.imports.fileManager1API;
const Utils = Me.imports.utils;
const WindowPreview = Me.imports.windowPreview;
const AppIconIndicators = Me.imports.appIconIndicators;
Expand Down Expand Up @@ -131,11 +130,14 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
this._updateIndicatorStyle.bind(this)
]);
}, this);
this._signalsHandler.add([
FileManager1API.fm1Client,
'windows-changed',
this.onWindowsChanged.bind(this)
]);

if (this._location) {
this._signalsHandler.add([
Docking.DockManager.getDefault().fm1Client,
'windows-changed',
this.onWindowsChanged.bind(this)
]);
}

this._signalsHandler.add([
Docking.DockManager.settings,
Expand Down Expand Up @@ -995,8 +997,8 @@ const MyAppIconMenu = class DashToDock_MyAppIconMenu extends AppDisplay.AppIconM
Signals.addSignalMethods(MyAppIconMenu.prototype);

function getWindows(app, location) {
if (location != null) {
return FileManager1API.fm1Client.getWindows(location);
if (location != null && Docking.DockManager.getDefault().fm1Client) {
return Docking.DockManager.getDefault().fm1Client.getWindows(location);
} else {
return app.get_windows();
}
Expand Down
35 changes: 34 additions & 1 deletion docking.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Intellihide = Me.imports.intellihide;
const Theming = Me.imports.theming;
const MyDash = Me.imports.dash;
const LauncherAPI = Me.imports.launcherAPI;
const FileManager1API = Me.imports.fileManager1API;

const DOCK_DWELL_CHECK_INTERVAL = 100;

Expand Down Expand Up @@ -1586,6 +1587,8 @@ var DockManager = class DashToDock_DockManager {
this._remoteModel = new LauncherAPI.LauncherEntryRemoteModel();
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.dash-to-dock');
this._oldDash = Main.overview._dash;
this._ensureFileManagerClient();

/* Array of all the docks created */
this._allDocks = [];
this._createDocks();
Expand All @@ -1606,6 +1609,24 @@ var DockManager = class DashToDock_DockManager {
return DockManager.getDefault()._settings;
}

get fm1Client() {
return this._fm1Client;
}

_ensureFileManagerClient() {
let supportsLocations = ['show-trash', 'show-mounts'].some((s) => {
return this._settings.get_boolean(s);
});

if (supportsLocations) {
if (!this._fm1Client)
this._fm1Client = new FileManager1API.FileManager1Client();
} else if (this._fm1Client) {
this._fm1Client.destroy();
this._fm1Client = null;
}
}

_toggle() {
this._deleteDocks();
this._createDocks();
Expand Down Expand Up @@ -1639,7 +1660,15 @@ var DockManager = class DashToDock_DockManager {
this._settings,
'changed::dock-fixed',
this._adjustPanelCorners.bind(this)
]);
], [
this._settings,
'changed::show-trash',
() => this._ensureFileManagerClient()
], [
this._settings,
'changed::show-mounts',
() => this._ensureFileManagerClient()
], );
}

_createDocks() {
Expand Down Expand Up @@ -1849,6 +1878,10 @@ var DockManager = class DashToDock_DockManager {
this._deleteDocks();
this._revertPanelCorners();
this._restoreDash();
if (this._fm1Client) {
this._fm1Client.destroy();
this._fm1Client = null;
}
this._remoteModel.destroy();
this._settings.run_dispose();
this._settings = null;
Expand Down
3 changes: 1 addition & 2 deletions fileManager1API.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var FileManager1Client = class DashToDock_FileManager1Client {

destroy() {
this._signalsHandler.destroy();
this._proxy.run_dispose();
}

/**
Expand Down Expand Up @@ -214,5 +215,3 @@ function guessWindowXID(win) {
return null;
}
}

var fm1Client = new FileManager1Client();

0 comments on commit 6bddbc3

Please sign in to comment.