Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait until the desktop ends starting up #231

Merged
merged 4 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions appIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ class AppIndicators_IconActor extends St.Icon {
}

_createIconByName(path, callback) {
if (!path) {
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the idle is needed here, can't we just call the callback and return here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I saw it was failing as per 6b5bd5c

Not sure there's another way to avoid.

In any case, pelase save the idle id in the class and disconnect it on destruction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I call it from IDLE to ensure that the calling code ends anything that is doing before the callback is called. Currently it doesn't matter, but being strict, the code that calls _createIconByName() can legally presume that the callback won't be called until the whole function ended. Calling the callback directly instead of using idle_add can result in breaking that assumption.

About the id: the callback already returns false to remove it, so it doesn't need to be disconnected on destruction. In fact, it MUST be removed after the first execution, or the callback would be called every time there is idle time.

(unless I understood the memory management wrong in these cases)

callback(null);
return false;
});
return;
}
GdkPixbuf.Pixbuf.get_file_info_async(path, this._cancellable, (_p, res) => {
try {
let [format, width, height] = GdkPixbuf.Pixbuf.get_file_info_finish(res);
Expand Down
43 changes: 39 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
const Gio = imports.gi.Gio
const GLib = imports.gi.GLib
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;

const Extension = imports.misc.extensionUtils.getCurrentExtension()

Expand All @@ -24,6 +28,10 @@ const Util = Extension.imports.util
let statusNotifierWatcher = null;
let isEnabled = false;
let watchDog = null;
let startupPreparedId = 0;
let waitForThemeId = 0;
let startupComplete = false;
let displayAvailable = false;

function init() {
watchDog = new NameWatchdog();
Expand Down Expand Up @@ -51,9 +59,36 @@ function maybe_enable_after_name_available() {
statusNotifierWatcher = new StatusNotifierWatcher.StatusNotifierWatcher(watchDog);
}

function inner_enable() {
if (startupComplete && displayAvailable) {
isEnabled = true;
maybe_enable_after_name_available();
}
}

function enable() {
isEnabled = true;
maybe_enable_after_name_available();
// If the desktop is still starting up, we must wait until it is ready
if (Main.layoutManager._startingUp) {
startupPreparedId = Main.layoutManager.connect('startup-complete', () => {
Main.layoutManager.disconnect(startupPreparedId);
startupComplete = true;
inner_enable();
});
} else {
startupComplete = true;
}

// Ensure that the default Gdk Screen is available
if (Gtk.IconTheme.get_default() == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe here would be better to check !Gdk.DisplayManager.get().get_default_display() instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gtk.IconTheme.get_default() fails because internally it can't get the default display. In some comments in #mutter they commented that Gtk.IconTheme should not rely on a display (or an screen... now I doubt), because it is an X11 specific structure. So, if in the future, they remove that, Gtk.IconTheme.get_default() will work directly and the extension won't have to wait.

waitForThemeId = Gdk.DisplayManager.get().connect('display-opened', () => {
Gdk.DisplayManager.get().disconnect(waitForThemeId);
displayAvailable = true;
inner_enable();
});
} else {
displayAvailable = true;
}
inner_enable();
}

function disable() {
Expand Down