Debian Codegraph @

src/application.js

raw
1 /* exported FlatsealApplication */
2 /* eslint class-methods-use-this: */
3
4 /* application.js
5 *
6 * Copyright 2020 Martin Abente Lahaye
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 const {GObject, Gtk, Gio, GLib, Adw} = imports.gi;
23
24 const {FlatsealWindow} = imports.widgets.window;
25 const {showAboutDialog} = imports.widgets.aboutDialog;
26 const {FlatsealDocsViewer} = imports.widgets.docsViewer;
27
28 var FlatsealApplication = GObject.registerClass({
29 GTypeName: 'FlatsealApplication',
30 }, class FlatsealApplication extends Adw.Application {
31 _init() {
32 super._init({
33 application_id: 'com.github.tchx84.Flatseal',
34 flags: Gio.ApplicationFlags.FLAGS_NONE,
35 resource_base_path: '/com/github/tchx84/Flatseal/',
36 });
37
38 this._window = null;
39 }
40
41 _displayHelp() {
42 this.activate();
43 const launcher = new Gtk.UriLauncher();
44 launcher.uri = 'https://github.com/tchx84/flatseal';
45 launcher.launch(this._window, null, this._doDisplayHelp);
46 }
47
48 _doDisplayHelp(launcher, res) {
49 try {
50 launcher.launch_finish(res);
51 } catch (err) {
52 logError(err);
53 }
54 }
55
56 _displayDocumentation() {
57 this.activate();
58 const viewer = new FlatsealDocsViewer(this._window);
59 viewer.present();
60 }
61
62 _displayAbout() {
63 this.activate();
64 showAboutDialog(this._window);
65 }
66
67 _quit() {
68 this.activate();
69 this._window._shutdown();
70 this.quit();
71 }
72
73 _show(action, appId) {
74 this.activate();
75 this._window.showApplication(appId.unpack());
76 }
77
78 _setupActions() {
79 const help_action = new Gio.SimpleAction({name: 'help', state: null});
80 help_action.connect('activate', this._displayHelp.bind(this));
81
82 const documentation_action = new Gio.SimpleAction({name: 'documentation', state: null});
83 documentation_action.connect('activate', this._displayDocumentation.bind(this));
84
85 const about_action = new Gio.SimpleAction({name: 'about', state: null});
86 about_action.connect('activate', this._displayAbout.bind(this));
87
88 const quit_action = new Gio.SimpleAction({name: 'quit', state: null});
89 quit_action.connect('activate', this._quit.bind(this));
90
91 const show_action = new Gio.SimpleAction({name: 'show', state: null, parameterType: GLib.VariantType.new('s')});
92 show_action.connect('activate', this._show.bind(this));
93
94 this.add_action(help_action);
95 this.add_action(documentation_action);
96 this.add_action(about_action);
97 this.add_action(quit_action);
98 this.add_action(show_action);
99
100 this.set_accels_for_action('app.documentation', ['F1']);
101 this.set_accels_for_action('app.quit', ['<Control>q']);
102 this.set_accels_for_action('window.close', ['<Control>w']);
103 }
104
105 vfunc_activate() {
106 if (this._window === null)
107 this._window = new FlatsealWindow(this);
108
109 this._window.present();
110 }
111
112 vfunc_startup() {
113 super.vfunc_startup();
114 this._setupActions();
115 }
116 });