-
Notifications
You must be signed in to change notification settings - Fork 162
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
||
|
@@ -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(); | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe here would be better to check There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)