Skip to content

Commit c407917

Browse files
committed
application: remove RxJS
#389
1 parent 16bbe12 commit c407917

File tree

2 files changed

+105
-96
lines changed

2 files changed

+105
-96
lines changed

ddterm/app/application.js

+100-93
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const System = imports.system;
2424
const Me = imports.misc.extensionUtils.getCurrentExtension();
2525

2626
const { backport } = imports.ddterm;
27-
const { translations, simpleaction } = imports.ddterm.util;
27+
const { translations } = imports.ddterm.util;
2828
const { timers } = imports.ddterm.rx;
2929

3030
translations.init(Me.dir);
@@ -41,20 +41,27 @@ imports.ddterm.app.dependencies.gi_require({
4141

4242
const { Gdk, Gtk } = imports.gi;
4343

44-
const { rxjs } = imports.ddterm.thirdparty.rxjs;
45-
const { rxutil, settings } = imports.ddterm.rx;
44+
const { AppWindow } = imports.ddterm.app.appwindow;
45+
const { PrefsDialog } = imports.ddterm.pref.dialog;
4646

4747
const APP_DIR = Me.dir.get_child('ddterm').get_child('app');
4848

4949
const Application = backport.GObject.registerClass(
5050
{
5151
Properties: {
52-
'preferences-visible': GObject.ParamSpec.boolean(
53-
'preferences-visible',
52+
'window': GObject.ParamSpec.object(
53+
'window',
5454
'',
5555
'',
56-
GObject.ParamFlags.READABLE | GObject.ParamFlags.EXPLICIT_NOTIFY,
57-
false
56+
GObject.ParamFlags.READWRITE | GObject.ParamFlags.EXPLICIT_NOTIFY,
57+
AppWindow
58+
),
59+
'prefs-dialog': GObject.ParamSpec.object(
60+
'prefs-dialog',
61+
'',
62+
'',
63+
GObject.ParamFlags.READWRITE | GObject.ParamFlags.EXPLICIT_NOTIFY,
64+
PrefsDialog
5865
),
5966
},
6067
},
@@ -97,14 +104,11 @@ const Application = backport.GObject.registerClass(
97104
null
98105
);
99106

100-
this.env_gdk_backend = null;
101-
this.unset_gdk_backend = false;
102-
103107
this.connect('startup', this.startup.bind(this));
104108
this.connect('handle-local-options', this.handle_local_options.bind(this));
105109

106-
this.window = null;
107-
this.prefs_dialog = null;
110+
this.env_gdk_backend = null;
111+
this.unset_gdk_backend = false;
108112
}
109113

110114
startup() {
@@ -114,41 +118,28 @@ const Application = backport.GObject.registerClass(
114118
if (this.env_gdk_backend !== null)
115119
GLib.setenv('GDK_BACKEND', this.env_gdk_backend, true);
116120

117-
this.rx = rxutil.scope(this, rxutil.signal(this, 'shutdown'));
118-
119-
const actions = {
120-
'quit': () => this.quit(),
121-
'preferences': () => this.preferences(),
122-
'begin-subscription-leak-check': () => rxutil.begin_subscription_leak_check(),
123-
'end-subscription-leak-check': () => rxutil.end_subscription_leak_check(),
124-
'gc': () => System.gc(),
125-
};
126-
127-
for (const [name, activate] of Object.entries(actions))
128-
this.add_action(new simpleaction.Action({ name, activate }));
129-
130-
this.add_action(new simpleaction.Action({
131-
name: 'dump-heap',
132-
activate: arg => this.dump_heap(arg.deepUnpack()),
133-
parameter_type: new GLib.VariantType('s'),
134-
}));
121+
this.simple_action('quit', () => this.quit());
122+
this.simple_action('preferences', () => this.preferences());
123+
this.simple_action('gc', () => System.gc());
135124

136-
const close_preferences_action = new simpleaction.Action({
137-
name: 'close-preferences',
138-
activate: () => this.close_preferences(),
139-
});
140-
141-
this.rx.subscribe(
142-
rxutil.property(this, 'preferences-visible'),
143-
rxutil.property(close_preferences_action, 'enabled')
125+
this.simple_action(
126+
'dump-heap',
127+
(_, param) => this.dump_heap(param.deepUnpack()),
128+
{ parameter_type: new GLib.VariantType('s') }
144129
);
145130

146-
this.add_action(close_preferences_action);
131+
const close_preferences_action = this.simple_action(
132+
'close-preferences',
133+
() => this.close_preferences(),
134+
{ enabled: false }
135+
);
147136

148-
this.settings = new settings.Settings({
149-
gsettings: imports.ddterm.util.settings.get_settings(),
137+
this.connect('notify::prefs-dialog', () => {
138+
close_preferences_action.enabled = this.prefs_dialog !== null;
150139
});
151140

141+
this.settings = imports.ddterm.util.settings.get_settings();
142+
152143
[
153144
'window-above',
154145
'window-stick',
@@ -161,24 +152,11 @@ const Application = backport.GObject.registerClass(
161152
'preserve-working-directory',
162153
'transparent-background',
163154
].forEach(key => {
164-
this.add_action(this.settings.gsettings.create_action(key));
155+
this.add_action(this.settings.create_action(key));
165156
});
166157

167-
const gtk_settings = Gtk.Settings.get_default();
168-
169-
this.rx.subscribe(
170-
this.settings.resolved['theme-variant'],
171-
theme => {
172-
if (theme === 'default')
173-
gtk_settings.reset_property('gtk-application-prefer-dark-theme');
174-
else if (theme === 'dark')
175-
gtk_settings.gtk_application_prefer_dark_theme = true;
176-
else if (theme === 'light')
177-
gtk_settings.gtk_application_prefer_dark_theme = false;
178-
else
179-
printerr(`Unknown theme-variant: ${theme}`);
180-
}
181-
);
158+
this.settings.connect('changed::theme-variant', this.update_theme.bind(this));
159+
this.update_theme();
182160

183161
const menus = Gtk.Builder.new_from_file(APP_DIR.get_child('menus.ui').get_path());
184162

@@ -190,10 +168,10 @@ const Application = backport.GObject.registerClass(
190168
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
191169
);
192170

193-
this.window = new imports.ddterm.app.appwindow.AppWindow({
171+
this.window = new AppWindow({
194172
application: this,
195173
decorated: this.decorated,
196-
settings: this.settings,
174+
gsettings: this.settings,
197175
menus,
198176
});
199177

@@ -234,26 +212,11 @@ const Application = backport.GObject.registerClass(
234212
for (let i = 0; i < 10; i += 1)
235213
shortcut_actions[`shortcut-switch-to-tab-${i + 1}`] = `win.switch-to-tab(${i})`;
236214

237-
const shortcuts_enabled = this.settings['shortcuts-enabled'];
238-
239-
const append_escape = rxjs.pipe(
240-
rxjs.combineLatestWith(this.settings['hide-window-on-esc']),
241-
rxjs.map(([shortcuts, append]) => append ? shortcuts.concat(['Escape']) : shortcuts)
242-
);
243-
244-
for (const [key, action] of Object.entries(shortcut_actions)) {
245-
this.rx.subscribe(
246-
rxutil.switch_on(shortcuts_enabled, {
247-
true: this.settings[key],
248-
false: rxjs.of([]),
249-
}).pipe(action === 'win.hide' ? append_escape : rxjs.identity),
250-
value => {
251-
this.set_accels_for_action(action, value);
252-
}
253-
);
254-
}
215+
Object.entries(shortcut_actions).forEach(([key, action]) => {
216+
this.bind_shortcut(action, key);
217+
});
255218

256-
this.rx.connect(this, 'activate', this.activate.bind(this));
219+
this.connect('activate', this.activate.bind(this));
257220
}
258221

259222
activate() {
@@ -297,20 +260,14 @@ const Application = backport.GObject.registerClass(
297260

298261
preferences() {
299262
if (this.prefs_dialog === null) {
300-
this.prefs_dialog = new imports.ddterm.pref.dialog.PrefsDialog({
263+
this.prefs_dialog = new PrefsDialog({
301264
transient_for: this.window,
302-
settings: this.settings.gsettings,
265+
settings: this.settings,
303266
});
304267

305-
this.rx.subscribe(
306-
rxutil.signal(this.prefs_dialog, 'delete-event').pipe(rxjs.take(1)),
307-
() => {
308-
this.prefs_dialog = null;
309-
this.notify('preferences-visible');
310-
}
311-
);
312-
313-
this.notify('preferences-visible');
268+
this.prefs_dialog.connect('destroy', () => {
269+
this.prefs_dialog = null;
270+
});
314271
}
315272

316273
this.prefs_dialog.show();
@@ -321,10 +278,6 @@ const Application = backport.GObject.registerClass(
321278
this.prefs_dialog.close();
322279
}
323280

324-
get preferences_visible() {
325-
return this.prefs_dialog !== null;
326-
}
327-
328281
dump_heap(path = null) {
329282
if (!path) {
330283
path = GLib.build_filenamev([
@@ -345,6 +298,60 @@ const Application = backport.GObject.registerClass(
345298
System.dumpHeap(path);
346299
printerr(`Dumped heap to ${path}`);
347300
}
301+
302+
simple_action(name, activate, params = {}) {
303+
const action = new Gio.SimpleAction({
304+
name,
305+
...params,
306+
});
307+
action.connect('activate', activate);
308+
this.add_action(action);
309+
return action;
310+
}
311+
312+
update_theme() {
313+
const gtk_settings = Gtk.Settings.get_default();
314+
const theme = this.settings.get_string('theme-variant');
315+
316+
switch (theme) {
317+
case 'system':
318+
gtk_settings.reset_property('gtk-application-prefer-dark-theme');
319+
break;
320+
321+
case 'dark':
322+
gtk_settings.gtk_application_prefer_dark_theme = true;
323+
break;
324+
325+
case 'light':
326+
gtk_settings.gtk_application_prefer_dark_theme = false;
327+
break;
328+
329+
default:
330+
printerr(`Unknown theme-variant: ${theme}`);
331+
}
332+
}
333+
334+
bind_shortcut(action, settings_key) {
335+
const handler = this.update_shortcut.bind(this, action, settings_key);
336+
337+
this.settings.connect(`changed::${settings_key}`, handler);
338+
this.settings.connect('changed::shortcuts-enabled', handler);
339+
340+
if (action === 'win.hide')
341+
this.settings.connect('changed::hide-window-on-esc', handler);
342+
343+
handler();
344+
}
345+
346+
update_shortcut(action, settings_key) {
347+
const enable = this.settings.get_boolean('shortcuts-enabled');
348+
const keys = enable ? this.settings.get_strv(settings_key) : [];
349+
350+
if (action === 'win.hide' && this.settings.get_boolean('hide-window-on-esc'))
351+
keys.push('Escape');
352+
353+
this.set_accels_for_action(action, keys);
354+
}
348355
}
349356
);
350357

ddterm/app/appwindow.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,21 @@ var AppWindow = backport.GObject.registerClass(
5858
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
5959
Gtk.Builder
6060
),
61-
'settings': GObject.ParamSpec.object(
62-
'settings',
61+
'gsettings': GObject.ParamSpec.object(
62+
'gsettings',
6363
'',
6464
'',
6565
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
66-
settings.Settings
66+
Gio.Settings
6767
),
6868
},
6969
},
7070
class AppWindow extends Gtk.ApplicationWindow {
7171
_init(params) {
7272
super._init(params);
7373

74+
this.settings = new settings.Settings({ gsettings: this.gsettings });
75+
7476
this.rx = rxutil.scope(this);
7577

7678
this.extension_dbus = extensiondbus.get();

0 commit comments

Comments
 (0)