Skip to content

Commit

Permalink
Preprocess JS sources
Browse files Browse the repository at this point in the history
  • Loading branch information
amezin committed Feb 10, 2024
1 parent 4ad9b8a commit 8b245c8
Show file tree
Hide file tree
Showing 28 changed files with 188 additions and 266 deletions.
2 changes: 2 additions & 0 deletions ddterm/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ gi_require({
'Gdk': '3.0',
'Pango': '1.0',
'Vte': '2.91',
// BEGIN ESM
'Handy': '1',
// END ESM
});
33 changes: 0 additions & 33 deletions ddterm/app/init.legacy.js

This file was deleted.

22 changes: 6 additions & 16 deletions ddterm/app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ app_js_files = files(
'dependencies.js',
'extensiondbus.js',
'heapdump.js',
'init.js',
'meta.js',
'notebook.js',
'pcre2.js',
'prefsdialog.js',
'resources.js',
'search.js',
'settings.js',
Expand All @@ -26,34 +28,22 @@ app_ui_files = files(
)

foreach app_file : app_js_files + app_ui_files + files('dependencies.json', 'style.css')
pack += fs.copyfile(
app_file,
pack += custom_target(
command: preprocess_command,
input: app_file,
output: fs.name(app_file),
install: true,
install_dir: extension_dir / 'ddterm' / 'app',
)
endforeach

pack += fs.copyfile(
get_option('esm') ? 'prefsdialog.js' : 'prefsdialog.legacy.js',
'prefsdialog.js',
install: true,
install_dir: extension_dir / 'ddterm' / 'app',
)

pack += fs.copyfile(
get_option('esm') ? 'gtktheme.js' : 'gtktheme.legacy.js',
'gtktheme.js',
install: true,
install_dir: extension_dir / 'ddterm' / 'app',
)

pack += fs.copyfile(
get_option('esm') ? 'init.js' : 'init.legacy.js',
'init.js',
install: true,
install_dir: extension_dir / 'ddterm' / 'app',
)

subdir('icons')

foreach app_ui_file : app_ui_files
Expand Down
53 changes: 50 additions & 3 deletions ddterm/app/prefsdialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2023 Aleksandr Mezin
Copyright © 2024 Aleksandr Mezin
This file is part of ddterm GNOME Shell extension.
Expand All @@ -17,14 +17,52 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import Gettext from 'gettext';

import { metadata } from './meta.js';
import { metadata, dir } from './meta.js';
// BEGIN ESM
import { PrefsWidget } from '../pref/widget.js';
// END ESM

// BEGIN !ESM
const [fakeext_import_path] = GLib.filename_from_uri(
GLib.Uri.resolve_relative(import.meta.url, 'fakeext', GLib.UriFlags.NONE)
);

imports.searchPath.unshift(fakeext_import_path);

const Me = imports.misc.extensionUtils.getCurrentExtension();

function make_dir_importer(file) {
/* Like extensionUtils.installImporter() */

const old_search_path = imports.searchPath.slice();

imports.searchPath = [file.get_parent().get_path()];

try {
return imports[file.get_basename()];
} finally {
imports.searchPath = old_search_path;
}
}

/*
* fake current extension object to make `Me.imports` and `Me.dir`
* work in application context
*/
Object.assign(Me, {
imports: make_dir_importer(dir),
dir,
path: dir.get_path(),
metadata,
});
// END !ESM

export const PrefsDialog = GObject.registerClass({
Properties: {
Expand All @@ -46,10 +84,19 @@ export const PrefsDialog = GObject.registerClass({
this.set_default_size(640, 576);
this.set_icon_name('preferences-system');

const widget = new PrefsWidget({
let widget;
// BEGIN ESM
widget = new PrefsWidget({
settings: this.settings,
gettext_context,
});
// END ESM
// BEGIN !ESM
widget = new Me.imports.ddterm.pref.widget.PrefsWidget({
settings: this.settings,
gettext_context,
});
// END !ESM

const content_area = this.get_content_area();

Expand Down
94 changes: 0 additions & 94 deletions ddterm/app/prefsdialog.legacy.js

This file was deleted.

9 changes: 5 additions & 4 deletions ddterm/app/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export function get_resource_binary(file_or_relative_url) {

export function get_resource_text(file_or_relative_url) {
const bytes = get_resource_binary(file_or_relative_url);

return globalThis.TextDecoder
? new TextDecoder().decode(bytes)
: imports.byteArray.toString(bytes);
// BEGIN !ESM
if (!globalThis.TextDecoder)
return imports.byteArray.toString(bytes);
// END !ESM
return new TextDecoder().decode(bytes);
}
5 changes: 2 additions & 3 deletions ddterm/pref/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import { ui_file_uri } from './resources.js';

import {
bind_sensitive,
bind_widgets,
insert_settings_actions,
set_scale_value_format
set_scale_value_format,
ui_file_uri
} from './util.js';

export const AnimationWidget = GObject.registerClass({
Expand Down
3 changes: 1 addition & 2 deletions ddterm/pref/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import { ui_file_uri } from './resources.js';
import { bind_widget, insert_settings_actions } from './util.js';
import { bind_widget, insert_settings_actions, ui_file_uri } from './util.js';

export const BehaviorWidget = GObject.registerClass({
GTypeName: 'DDTermPrefsBehavior',
Expand Down
5 changes: 2 additions & 3 deletions ddterm/pref/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import Gio from 'gi://Gio';
import Gdk from 'gi://Gdk';
import Gtk from 'gi://Gtk';

import { ui_file_uri } from './resources.js';

import {
bind_sensitive,
bind_widget,
insert_settings_actions,
set_scale_value_format
set_scale_value_format,
ui_file_uri
} from './util.js';

function show_dialog(parent_window, message, message_type = Gtk.MessageType.ERROR) {
Expand Down
3 changes: 1 addition & 2 deletions ddterm/pref/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import { ui_file_uri } from './resources.js';
import { bind_widget, insert_settings_actions } from './util.js';
import { bind_widget, insert_settings_actions, ui_file_uri } from './util.js';

export const CommandWidget = GObject.registerClass({
GTypeName: 'DDTermPrefsCommand',
Expand Down
3 changes: 1 addition & 2 deletions ddterm/pref/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import { ui_file_uri } from './resources.js';
import { bind_widgets } from './util.js';
import { bind_widgets, ui_file_uri } from './util.js';

export const CompatibilityWidget = GObject.registerClass({
GTypeName: 'DDTermPrefsCompatibility',
Expand Down
23 changes: 12 additions & 11 deletions ddterm/pref/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@ pref_copy_files = []

foreach pref_file : pref_files
if get_option('esm')
pref_copy_files += fs.copyfile(
pref_file,
pref_copy_files += custom_target(
command: preprocess_command,
input: pref_file,
output: fs.name(pref_file),
install: true,
install_dir: extension_dir / 'ddterm' / 'pref',
)
else
pref_copy_files += custom_target(
command: gjs_translate_esm,
preproc = custom_target(
command: preprocess_command,
input: pref_file,
output: fs.name(pref_file) + '.sed',
)

pref_copy_files += custom_target(
command: [gjs_translate_esm, '-o', '@OUTPUT@', '-d', meson.project_build_root(), '@INPUT@'],
input: preproc,
output: fs.name(pref_file),
install: true,
install_dir: extension_dir / 'ddterm' / 'pref',
)
endif
endforeach

pref_copy_files += fs.copyfile(
get_option('esm') ? 'resources.js' : 'resources.legacy.js',
'resources.js',
install: true,
install_dir: extension_dir / 'ddterm' / 'pref',
)

pack += pref_copy_files

subdir('ui')
Expand Down
3 changes: 1 addition & 2 deletions ddterm/pref/panelicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import { ui_file_uri } from './resources.js';
import { insert_settings_actions } from './util.js';
import { insert_settings_actions, ui_file_uri } from './util.js';

export const PanelIconWidget = GObject.registerClass({
GTypeName: 'DDTermPrefsPanelIcon',
Expand Down
Loading

0 comments on commit 8b245c8

Please sign in to comment.