[sushi/wip/cosimoc/no-clutter: 46/50] Add an inactivity timeout to the application instance
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi/wip/cosimoc/no-clutter: 46/50] Add an inactivity timeout to the application instance
- Date: Mon, 17 Jun 2019 18:36:28 +0000 (UTC)
commit 838216e90f013d70586faa77267bf1b857de206a
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Jun 15 18:48:29 2019 -0700
Add an inactivity timeout to the application instance
So that we can reuse the process in case another request comes in
before the inactivity timeout expires.
src/ui/application.js | 17 ++++++++++++-----
src/ui/main.js | 8 +++++++-
src/ui/mainWindow.js | 5 +++++
3 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/src/ui/application.js b/src/ui/application.js
index b3feb2b..20523cc 100644
--- a/src/ui/application.js
+++ b/src/ui/application.js
@@ -46,7 +46,6 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
super.vfunc_startup();
this._defineStyleAndThemes();
- this._createMainWindow();
}
vfunc_dbus_register(connection, path) {
@@ -59,9 +58,14 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
vfunc_activate() {
}
- _createMainWindow() {
- this._mainWindow =
- new MainWindow.MainWindow(this);
+ _ensureMainWindow() {
+ if (this._mainWindow)
+ return;
+
+ this._mainWindow = new MainWindow.MainWindow(this);
+ this._mainWindow.connect('destroy', () => {
+ this._mainWindow = null;
+ });
}
_defineStyleAndThemes() {
@@ -76,10 +80,13 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
}
Close() {
- this._mainWindow.destroy();
+ if (this._mainWindow)
+ this._mainWindow.destroy();
}
ShowFile(uri, xid, closeIfAlreadyShown) {
+ this._ensureMainWindow();
+
let file = Gio.file_new_for_uri(uri);
if (closeIfAlreadyShown &&
this._mainWindow.file &&
diff --git a/src/ui/main.js b/src/ui/main.js
index e8ccb50..ae37075 100644
--- a/src/ui/main.js
+++ b/src/ui/main.js
@@ -40,11 +40,17 @@ pkg.require({
WebKit2: '4.0',
});
+const {Gio, GLib} = imports.gi;
+
const Application = imports.ui.application;
const SUSHI_DBUS_NAME = 'org.gnome.NautilusPreviewer';
function main(argv) {
- let application = new Application.Application({ application_id: SUSHI_DBUS_NAME });
+ let application = new Application.Application({ application_id: SUSHI_DBUS_NAME,
+ flags: Gio.ApplicationFlags.IS_SERVICE,
+ inactivity_timeout: 12000 });
+ if (GLib.getenv('SUSHI_PERSIST'))
+ application.hold();
return application.run(argv);
}
diff --git a/src/ui/mainWindow.js b/src/ui/mainWindow.js
index aee6650..afa9b71 100644
--- a/src/ui/mainWindow.js
+++ b/src/ui/mainWindow.js
@@ -79,6 +79,7 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
this.set_titlebar(this._titlebar);
this.connect('delete-event', this._onDeleteEvent.bind(this));
+ this.connect('destroy', this._onDestroy.bind(this));
this.connect('key-press-event', this._onKeyPressEvent.bind(this));
this.connect('motion-notify-event', this._onMotionNotifyEvent.bind(this));
this.connect('realize', this._onRealize.bind(this));
@@ -98,6 +99,10 @@ var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
this.destroy();
}
+ _onDestroy() {
+ this._removeToolbarTimeout();
+ }
+
_onRealize() {
// don't support maximize and minimize
this.get_window().set_functions(Gdk.WMFunction.MOVE |
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]