How to interact with the MainLoop ?



I'm trying to figure out if there's a way to avoid GJS exiting when there are operations going on, like a watch on a file, or folder, without bothering the main Gtk loop or `imports.mainloop.run()`

What I'd really like to do, is to understand if any other part of the code started already a loop but I cannot find a way to reach `g_main_loop_is_running()` via GJS and using `null` to receive the context, when I should also pass the value `isRunning` makes little sense to me ... 'cause I don't know upfront if I want the default context flagged as running or not.

The `Gtk.main_level()` gives me 0 even if `imports.mainloop.run()` has never been called, and it gives me 1 or more even if a `Gtk.main_quit()` has been invoked after.

Registering a callback in the mainloop also doesn't prevent GJS from exiting before it's triggered.

I've tried to use `Gio.Application` with a dummy listener and using `app.hold()` but the moment I follow that command by `app.run([])` nothing after happens, so I can't set this thing up as it unless I do it after another event has been scheduled.

This makes sense because `hold` and `release` are explicit in their intent, but I feel like there's no way to do what I'm trying to do.

Let's say this is my `gjs-info` program

```gjs
#!/usr/bin/env gjs
const Gio = imports.gi.Gio;
let fd = Gio.File.new_for_path(ARGV[0]);
fd.query_info_async('*', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null, null, (source, result) => {
  let info = source.query_info_finish(result);
  print(info);
});

// if I write this, it will hang
// if I don't, it will exit
// imports.mainloop.run();
```

considering this is an example and what I'm trying to do has many nested asynchronous operations and not just one, how could I prevent GJS from exiting the program before I have results?

Thanks for any sort of hint/outcome.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]