[polari] Port to ES modules



commit ff19867ad214888d53381e14f1caa73e6b97d704
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Feb 7 13:36:49 2021 +0100

    Port to ES modules
    
    gjs gained support for ES modules, which gives us a standardized way
    for imports/exports (with an extension for GI libraries) rather than
    the custom system that's in use now.
    
    https://gitlab.gnome.org/GNOME/polari/-/merge_requests/176

 lint/eslintrc-polari.yml |  2 ++
 meson.build              |  2 +-
 src/accountsMonitor.js   | 12 ++++++++----
 src/appNotifications.js  | 32 +++++++++++++++++++++-----------
 src/application.js       | 40 +++++++++++++++++++++++-----------------
 src/chatView.js          | 32 +++++++++++++++++++-------------
 src/config.js.in         |  8 ++++----
 src/connections.js       | 24 ++++++++++++++++--------
 src/entryArea.js         | 35 ++++++++++++++++++++++-------------
 src/initialSetup.js      | 12 ++++++++----
 src/ircParser.js         | 17 ++++++++++-------
 src/joinDialog.js        | 14 +++++++++-----
 src/main.js              | 35 +++++++++++++++++++++--------------
 src/mainWindow.js        | 41 ++++++++++++++++++++++++++---------------
 src/networksManager.js   |  8 +++++---
 src/pasteManager.js      | 19 ++++++++++++++-----
 src/polari.c             | 15 ++++++---------
 src/roomList.js          | 29 +++++++++++++++++++----------
 src/roomManager.js       | 12 ++++++++----
 src/roomStack.js         | 20 ++++++++++++--------
 src/serverRoomManager.js | 23 ++++++++++++++++-------
 src/tabCompletion.js     | 10 ++++++----
 src/telepathyClient.js   | 18 +++++++++++-------
 src/thumbnailer.js       | 12 +++++++-----
 src/urlPreview.js        | 13 +++++++++----
 src/userList.js          | 31 ++++++++++++++++++++-----------
 src/userTracker.js       | 16 ++++++++++------
 src/utils.js             | 39 +++++++++++++++++++++++++++++----------
 28 files changed, 362 insertions(+), 209 deletions(-)
---
diff --git a/lint/eslintrc-polari.yml b/lint/eslintrc-polari.yml
index 527b28c7..a7ff1fcc 100644
--- a/lint/eslintrc-polari.yml
+++ b/lint/eslintrc-polari.yml
@@ -18,3 +18,5 @@ globals:
   C_: readonly
   N_: readonly
   ngettext: readonly
+parserOptions:
+  sourceType: module
diff --git a/meson.build b/meson.build
index 02993fcc..e7fb0e04 100644
--- a/meson.build
+++ b/meson.build
@@ -36,7 +36,7 @@ gio = dependency('gio-2.0', version: '>= 2.43.4')
 gtk3 = dependency('gtk+-3.0', version: '>= 3.21.6')
 telepathy_glib = dependency('telepathy-glib')
 girepository = dependency('gobject-introspection-1.0')
-gjs = dependency('gjs-1.0', version: '>= 1.57.3')
+gjs = dependency('gjs-1.0', version: '>= 1.67.2')
 
 conf = configuration_data()
 
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index e95b072f..16c56cef 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -1,15 +1,19 @@
-/* exported AccountsMonitor */
+export { AccountsMonitor };
+
+import Gio from 'gi://Gio';
+import GObject from 'gi://GObject';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
 
-const { Gio, GObject, Polari, TelepathyGLib: Tp } = imports.gi;
 const Signals = imports.signals;
 
-const { NetworksManager } = imports.networksManager;
+import { NetworksManager } from './networksManager.js';
 
 Gio._promisify(Tp.AccountManager.prototype, 'prepare_async', 'prepare_finish');
 Gio._promisify(Tp.Account.prototype,
     'request_presence_async', 'request_presence_finish');
 
-var AccountsMonitor = class {
+const AccountsMonitor = class {
     static getDefault() {
         if (!this._singleton)
             this._singleton = new AccountsMonitor();
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 12727b69..cbc893a7 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -1,7 +1,17 @@
-/* exported MessageNotification UndoNotification NotificationQueue
-            SimpleOutput GridOutput CommandOutputQueue MessageInfoBar */
-
-const { GLib, GObject, Gtk, Pango } = imports.gi;
+export {
+    MessageNotification,
+    UndoNotification,
+    NotificationQueue,
+    SimpleOutput,
+    GridOutput,
+    CommandOutputQueue,
+    MessageInfoBar
+};
+
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Pango from 'gi://Pango';
 
 const TIMEOUT = 7;
 const COMMAND_OUTPUT_REVEAL_TIME = 3;
@@ -28,7 +38,7 @@ const AppNotification = GObject.registerClass({
     }
 });
 
-var MessageNotification = GObject.registerClass(
+const MessageNotification = GObject.registerClass(
 class MessageNotification extends AppNotification {
     _init(label, iconName) {
         super._init();
@@ -68,7 +78,7 @@ class MessageNotification extends AppNotification {
     }
 });
 
-var UndoNotification = GObject.registerClass({
+const UndoNotification = GObject.registerClass({
     Signals: {
         closed: {},
         undo: {},
@@ -109,7 +119,7 @@ const CommandOutputNotification = GObject.registerClass({
     }
 });
 
-var SimpleOutput = GObject.registerClass(
+const SimpleOutput = GObject.registerClass(
 class SimpleOutput extends CommandOutputNotification {
     _init(text) {
         super._init();
@@ -125,7 +135,7 @@ class SimpleOutput extends CommandOutputNotification {
     }
 });
 
-var GridOutput = GObject.registerClass(
+const GridOutput = GObject.registerClass(
 class GridOutput extends CommandOutputNotification {
     _init(header, items) {
         super._init();
@@ -157,7 +167,7 @@ class GridOutput extends CommandOutputNotification {
     }
 });
 
-var NotificationQueue = GObject.registerClass(
+const NotificationQueue = GObject.registerClass(
 class NotificationQueue extends Gtk.Frame {
     _init() {
         super._init({
@@ -188,7 +198,7 @@ class NotificationQueue extends Gtk.Frame {
     }
 });
 
-var CommandOutputQueue = GObject.registerClass(
+const CommandOutputQueue = GObject.registerClass(
 class CommandOutputQueue extends NotificationQueue {
     _init() {
         super._init();
@@ -198,7 +208,7 @@ class CommandOutputQueue extends NotificationQueue {
     }
 });
 
-var MessageInfoBar = GObject.registerClass({
+const MessageInfoBar = GObject.registerClass({
     Properties: {
         'title': GObject.ParamSpec.string(
             'title', 'title', 'title',
diff --git a/src/application.js b/src/application.js
index 7c36108c..46d6a078 100644
--- a/src/application.js
+++ b/src/application.js
@@ -1,19 +1,25 @@
-/* exported Application */
-
-const { Gdk, Gio, GLib, GObject, Gtk, Polari, TelepathyGLib: Tp } = imports.gi;
-
-const { AccountsMonitor } = imports.accountsMonitor;
-const AppNotifications = imports.appNotifications;
-const Connections = imports.connections;
-const { InitialSetupWindow } = imports.initialSetup;
-const { MainWindow } = imports.mainWindow;
-const { NetworksManager } = imports.networksManager;
-const { PasteManager } = imports.pasteManager;
-const { RoomManager } = imports.roomManager;
-const { ServerRoomManager } = imports.serverRoomManager;
-const { TelepathyClient } = imports.telepathyClient;
-const { UserStatusMonitor } = imports.userTracker;
-const Utils = imports.utils;
+export { Application };
+
+import Gdk from 'gi://Gdk?version=3.0';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk?version=3.0';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
+
+import { AccountsMonitor } from './accountsMonitor.js';
+import * as AppNotifications from './appNotifications.js';
+import * as Connections from './connections.js';
+import { InitialSetupWindow } from './initialSetup.js';
+import { MainWindow } from './mainWindow.js';
+import { NetworksManager } from './networksManager.js';
+import { PasteManager } from './pasteManager.js';
+import { RoomManager } from './roomManager.js';
+import { ServerRoomManager } from './serverRoomManager.js';
+import { TelepathyClient } from './telepathyClient.js';
+import { UserStatusMonitor } from './userTracker.js';
+import * as Utils from './utils.js';
 
 Gio._promisify(Tp.AccountRequest.prototype,
     'create_account_async', 'create_account_finish');
@@ -31,7 +37,7 @@ const MAX_RETRIES = 3;
 
 const IRC_SCHEMA_REGEX = /^(irc?:\/\/)([\da-z.-]+):?(\d+)?\/(?:%23)?([\w.+-]+)/i;
 
-var Application = GObject.registerClass({
+const Application = GObject.registerClass({
     Signals: {
         'prepare-shutdown': {},
         'room-focus-changed': {},
diff --git a/src/chatView.js b/src/chatView.js
index 34f12b5c..9eb94b4d 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1,15 +1,21 @@
-/* exported ChatView */
-
-const {
-    Gdk, Gio, GLib, GObject, Gtk, Pango, PangoCairo, Polari,
-    TelepathyGLib: Tp, TelepathyLogger: Tpl,
-} = imports.gi;
-
-const { DropTargetIface } = imports.pasteManager;
-const { UserPopover } = imports.userList;
-const { UserStatusMonitor } = imports.userTracker;
-const { URLPreview } = imports.urlPreview;
-const Utils = imports.utils;
+export { ChatView };
+
+import Gdk from 'gi://Gdk';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Pango from 'gi://Pango';
+import PangoCairo from 'gi://PangoCairo';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
+import Tpl from 'gi://TelepathyLogger';
+
+import { DropTargetIface } from './pasteManager.js';
+import { UserPopover } from './userList.js';
+import { UserStatusMonitor } from './userTracker.js';
+import { URLPreview } from './urlPreview.js';
+import * as Utils from './utils.js';
 
 Gio._promisify(Tpl.LogWalker.prototype,
     'get_events_async', 'get_events_finish');
@@ -276,7 +282,7 @@ const HoverFilterTag = GObject.registerClass({
     }
 });
 
-var ChatView = GObject.registerClass({
+const ChatView = GObject.registerClass({
     Implements: [DropTargetIface],
     Properties: {
         'can-drop': GObject.ParamSpec.override('can-drop', DropTargetIface),
diff --git a/src/config.js.in b/src/config.js.in
index c2fea8f1..a49f4e8e 100644
--- a/src/config.js.in
+++ b/src/config.js.in
@@ -1,4 +1,4 @@
-var PACKAGE_NAME = '@PACKAGE_NAME@';
-var PACKAGE_VERSION = '@PACKAGE_VERSION@';
-var PREFIX = '@PREFIX@';
-var LIBDIR = '@LIBDIR@';
+export const PACKAGE_NAME = '@PACKAGE_NAME@';
+export const PACKAGE_VERSION = '@PACKAGE_VERSION@';
+export const PREFIX = '@PREFIX@';
+export const LIBDIR = '@LIBDIR@';
diff --git a/src/connections.js b/src/connections.js
index 9c521c17..e00a89b8 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -1,10 +1,18 @@
-/* exported ConnectionProperties ConnectionDetails ConnectionsList */
+export {
+    ConnectionProperties,
+    ConnectionDetails,
+    ConnectionsList
+};
 
-const { Gio, GLib, GObject, Gtk, TelepathyGLib: Tp } = imports.gi;
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Tp from 'gi://TelepathyGLib';
 
-const { AccountsMonitor } = imports.accountsMonitor;
-const { NetworksManager } = imports.networksManager;
-const Utils = imports.utils;
+import { AccountsMonitor } from './accountsMonitor.js';
+import { NetworksManager } from './networksManager.js';
+import * as Utils from './utils.js';
 
 Gio._promisify(Tp.Account.prototype,
     'set_display_name_async', 'set_display_name_finish');
@@ -72,7 +80,7 @@ class ConnectionRow extends Gtk.ListBoxRow {
     }
 });
 
-var ConnectionsList = GObject.registerClass({
+const ConnectionsList = GObject.registerClass({
     Properties: {
         'favorites-only': GObject.ParamSpec.boolean(
             'favorites-only', 'favorites-only', 'favorites-only',
@@ -259,7 +267,7 @@ var ConnectionsList = GObject.registerClass({
     }
 });
 
-var ConnectionDetails = GObject.registerClass({
+const ConnectionDetails = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/connection-details.ui',
     InternalChildren: [
         'nameEntry',
@@ -500,7 +508,7 @@ var ConnectionDetails = GObject.registerClass({
 });
 
 
-var ConnectionProperties = GObject.registerClass({
+const ConnectionProperties = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/connection-properties.ui',
     InternalChildren: [
         'details',
diff --git a/src/entryArea.js b/src/entryArea.js
index 6e7a6583..94d225e2 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -1,13 +1,22 @@
-/* exported ChatEntry EntryArea NickPopover */
-
-const {
-    Gdk, GdkPixbuf, Gio, GLib, GObject, Gspell, Gtk, TelepathyGLib: Tp,
-} = imports.gi;
-
-const ChatView = imports.chatView;
-const { DropTargetIface } = imports.pasteManager;
-const { IrcParser } = imports.ircParser;
-const { TabCompletion } = imports.tabCompletion;
+export {
+    ChatEntry,
+    EntryArea,
+    NickPopover
+};
+
+import Gdk from 'gi://Gdk';
+import GdkPixbuf from 'gi://GdkPixbuf';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gspell from 'gi://Gspell';
+import Gtk from 'gi://Gtk';
+import Tp from 'gi://TelepathyGLib';
+
+import * as ChatView from './chatView.js';
+import { DropTargetIface } from './pasteManager.js';
+import { IrcParser } from './ircParser.js';
+import { TabCompletion } from './tabCompletion.js';
 
 const MAX_NICK_UPDATE_TIME = 5; /* s */
 const MAX_LINES = 5;
@@ -15,7 +24,7 @@ const MAX_LINES = 5;
 Gio._promisify(Gio._LocalFilePrototype,
     'query_info_async', 'query_info_finish');
 
-var ChatEntry = GObject.registerClass({
+const ChatEntry = GObject.registerClass({
     Implements: [DropTargetIface],
     Properties: {
         'can-drop': GObject.ParamSpec.override('can-drop', DropTargetIface),
@@ -106,7 +115,7 @@ var ChatEntry = GObject.registerClass({
     }
 });
 
-var NickPopover = GObject.registerClass({
+const NickPopover = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/nick-popover.ui',
     InternalChildren: [
         'nickEntry',
@@ -154,7 +163,7 @@ var NickPopover = GObject.registerClass({
     }
 });
 
-var EntryArea = GObject.registerClass({
+const EntryArea = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/entry-area.ui',
     InternalChildren: [
         'chatEntry',
diff --git a/src/initialSetup.js b/src/initialSetup.js
index b46cfdc1..06160d1c 100644
--- a/src/initialSetup.js
+++ b/src/initialSetup.js
@@ -1,8 +1,12 @@
-/* exported InitialSetupWindow */
+export { InitialSetupWindow };
 
-const { Gio, GLib, GObject, Gtk, TelepathyGLib: Tp } = imports.gi;
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Tp from 'gi://TelepathyGLib';
 
-const Utils = imports.utils;
+import * as Utils from './utils.js';
 
 Gio._promisify(Tp.Account.prototype, 'remove_async', 'remove_finish');
 
@@ -12,7 +16,7 @@ const SetupPage = {
     OFFLINE: 2,
 };
 
-var InitialSetupWindow = GObject.registerClass({
+const InitialSetupWindow = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/initial-setup-window.ui',
     InternalChildren: [
         'contentStack',
diff --git a/src/ircParser.js b/src/ircParser.js
index 66434a0a..c41a93cf 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -1,11 +1,14 @@
-/* exported IrcParser */
+export { IrcParser };
+
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import Tp from 'gi://TelepathyGLib';
 
-const { Gio, GLib, TelepathyGLib: Tp } = imports.gi;
 const Signals = imports.signals;
 
-const AppNotifications = imports.appNotifications;
-const { RoomManager } = imports.roomManager;
-const Utils = imports.utils;
+import * as AppNotifications from './appNotifications.js';
+import { RoomManager } from './roomManager.js';
+import * as Utils from './utils.js';
 
 Gio._promisify(Tp.Account.prototype,
     'request_presence_async', 'request_presence_finish');
@@ -16,7 +19,7 @@ Gio._promisify(Tp.Contact.prototype,
 
 const N_ = s => s;
 
-var knownCommands = {
+export const knownCommands = {
     /* commands that would be nice to support: */
     /*
     AWAY: N_("/AWAY [<message>] — sets or unsets away message"),
@@ -45,7 +48,7 @@ var knownCommands = {
 const UNKNOWN_COMMAND_MESSAGE =
     N_('Unknown command — try /HELP for a list of available commands');
 
-var IrcParser = class {
+const IrcParser = class IrcParser {
     constructor(room) {
         this._app = Gio.Application.get_default();
         this._roomManager = RoomManager.getDefault();
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 8c1287d6..2cad5dba 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -1,16 +1,20 @@
-/* exported JoinDialog */
+export { JoinDialog };
 
-const { Gdk, Gio, GLib, GObject, Gtk } = imports.gi;
+import Gdk from 'gi://Gdk';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
 
-const { AccountsMonitor } = imports.accountsMonitor;
-const Utils = imports.utils;
+import { AccountsMonitor } from './accountsMonitor.js';
+import * as Utils from './utils.js';
 
 const DialogPage = {
     MAIN: 0,
     CONNECTION: 1,
 };
 
-var JoinDialog = GObject.registerClass({
+const JoinDialog = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/join-room-dialog.ui',
     InternalChildren: [
         'cancelButton',
diff --git a/src/main.js b/src/main.js
index b903ded6..87db61d1 100755
--- a/src/main.js
+++ b/src/main.js
@@ -1,8 +1,19 @@
-/* exported main */
+import GLib from 'gi://GLib';
+
+import * as Config from './config.js';
+import { ngettext } from 'gettext';
+import { programInvocationName } from 'system';
+
+imports.package.init({
+    name: Config.PACKAGE_NAME,
+    version: Config.PACKAGE_VERSION,
+    prefix: Config.PREFIX,
+    libdir: Config.LIBDIR,
+});
 
 pkg.initFormat();
 pkg.initGettext();
-globalThis.ngettext = imports.gettext.ngettext;
+globalThis.ngettext = ngettext;
 
 pkg.require({
     'GdkPixbuf': '2.0',
@@ -19,9 +30,7 @@ pkg.requireSymbol('GLib', '2.0', 'log_variant');
 pkg.requireSymbol('Gspell', '1', 'Entry');
 pkg.requireSymbol('Gtk', '3.0', 'ScrolledWindow.propagate_natural_width');
 
-const { GLib } = imports.gi;
-
-const { Application } = imports.application;
+import { Application } from './application.js';
 
 var LOG_DOMAIN = 'Polari';
 
@@ -52,13 +61,11 @@ globalThis.warning  = _makeLogFunction(GLib.LogLevelFlags.LEVEL_WARNING);
 globalThis.critical = _makeLogFunction(GLib.LogLevelFlags.LEVEL_CRITICAL);
 globalThis.error    = _makeLogFunction(GLib.LogLevelFlags.LEVEL_ERROR);
 
-function main(args) {
-    // Log all messages when connected to the journal
-    if (GLib.log_writer_is_journald(2))
-        GLib.setenv('G_MESSAGES_DEBUG', LOG_DOMAIN, false);
+// Log all messages when connected to the journal
+if (GLib.log_writer_is_journald(2))
+    GLib.setenv('G_MESSAGES_DEBUG', LOG_DOMAIN, false);
 
-    let application = new Application();
-    if (GLib.getenv('POLARI_PERSIST'))
-        application.hold();
-    return application.run(args);
-}
+let application = new Application();
+if (GLib.getenv('POLARI_PERSIST'))
+    application.hold();
+application.run([programInvocationName, ...ARGV]);
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 735c84e4..001698e1 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -1,17 +1,28 @@
-/* exported MainWindow FixedSizeFrame RoomList RoomStack UserList */
-
-const { Gdk, Gio, GLib, GObject, Gtk, Polari, TelepathyGLib: Tp } = imports.gi;
-
-const { AccountsMonitor } = imports.accountsMonitor;
-const { JoinDialog } = imports.joinDialog;
-const RoomList = imports.roomList; // used in template
-const { RoomManager } = imports.roomManager;
-const RoomStack = imports.roomStack; // used in template
-const UserList = imports.userList; // used in template
-const Utils = imports.utils;
-
-
-var FixedSizeFrame = GObject.registerClass({
+export {
+    MainWindow,
+    FixedSizeFrame,
+    RoomList,
+    RoomStack,
+    UserList
+};
+
+import Gdk from 'gi://Gdk';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
+
+import { AccountsMonitor } from './accountsMonitor.js';
+import { JoinDialog } from './joinDialog.js';
+import * as RoomList from './roomList.js'; // used in template
+import { RoomManager } from './roomManager.js';
+import * as RoomStack from './roomStack.js'; // used in template
+import * as UserList from './userList.js'; // used in template
+import * as Utils from './utils.js';
+
+const FixedSizeFrame = GObject.registerClass({
     Properties: {
         height: GObject.ParamSpec.int(
             'height', 'height', 'height',
@@ -74,7 +85,7 @@ var FixedSizeFrame = GObject.registerClass({
     }
 });
 
-var MainWindow = GObject.registerClass({
+const MainWindow = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/main-window.ui',
     InternalChildren: [
         'titlebarRight',
diff --git a/src/networksManager.js b/src/networksManager.js
index d6daf55d..7d54c125 100644
--- a/src/networksManager.js
+++ b/src/networksManager.js
@@ -1,10 +1,12 @@
-/* exported NetworksManager */
+export { NetworksManager };
+
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
 
-const { Gio, GLib } = imports.gi;
 const ByteArray = imports.byteArray;
 const Signals = imports.signals;
 
-var NetworksManager = class {
+const NetworksManager = class {
     static getDefault() {
         if (!this._singleton)
             this._singleton = new NetworksManager();
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 7ddf82ae..b44b20fa 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -1,8 +1,17 @@
-/* exported PasteManager DropTargetIface */
+export {
+    PasteManager,
+    DropTargetIface
+};
 
-const { Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk, Polari } = imports.gi;
+import Gdk from 'gi://Gdk';
+import GdkPixbuf from 'gi://GdkPixbuf';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Polari from 'gi://Polari';
 
-const Utils = imports.utils;
+import * as Utils from './utils.js';
 
 Gio._promisify(Gio._LocalFilePrototype,
     'load_contents_async', 'load_contents_finish');
@@ -29,7 +38,7 @@ function _getTargetForContentType(contentType) {
 }
 
 
-var PasteManager = class {
+const PasteManager = class {
     pasteContent(content, title) {
         if (typeof content === 'string')
             return Utils.gpaste(content, title);
@@ -64,7 +73,7 @@ var PasteManager = class {
     }
 };
 
-var DropTargetIface = GObject.registerClass({
+const DropTargetIface = GObject.registerClass({
     Requires: [GObject.Object],
     Properties: {
         'can-drop': GObject.ParamSpec.boolean(
diff --git a/src/polari.c b/src/polari.c
index f6e5d0dd..eeec766a 100644
--- a/src/polari.c
+++ b/src/polari.c
@@ -5,12 +5,7 @@
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GjsContext, g_object_unref)
 
-const char *src =
-  "const Config = imports.config;"
-  "imports.package.start({ name: Config.PACKAGE_NAME,"
-  "                        version: Config.PACKAGE_VERSION,"
-  "                        prefix: Config.PREFIX,"
-  "                        libdir: Config.LIBDIR });";
+#define JS_MAIN "resource:///org/gnome/Polari/js/main.js"
 
 static char **
 get_js_argv (int argc, const char * const *argv)
@@ -69,7 +64,8 @@ main (int argc, char *argv[])
   g_auto (GStrv) js_argv = NULL;
   GjsProfiler *profiler = NULL;
   gboolean debugger = FALSE;
-  int status, profiler_fd;
+  int profiler_fd;
+  uint8_t status;
 
   GOptionEntry entries[] =
     {
@@ -119,8 +115,9 @@ main (int argc, char *argv[])
       gjs_profiler_start (profiler);
     }
 
-  if (!gjs_context_eval (context, src, -1, "<main>", &status, &error))
-    g_message ("Execution of start() threw exception: %s", error->message);
+  if (!gjs_context_register_module (context, "<main>", JS_MAIN, &error) ||
+      !gjs_context_eval_module (context, "<main>", &status, &error))
+    g_message ("Execution of main.js threw exception: %s", error->message);
 
   if (profiler)
     gjs_profiler_stop (profiler);
diff --git a/src/roomList.js b/src/roomList.js
index b79e6496..7cef3325 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -1,10 +1,19 @@
-/* exported RoomList RoomListHeader RoomRow */
-
-const { Gdk, Gio, GLib, GObject, Gtk, TelepathyGLib: Tp } = imports.gi;
-
-const { AccountsMonitor } = imports.accountsMonitor;
-const { RoomManager } = imports.roomManager;
-const { UserStatusMonitor } = imports.userTracker;
+export {
+    RoomList,
+    RoomListHeader,
+    RoomRow
+};
+
+import Gdk from 'gi://Gdk';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Tp from 'gi://TelepathyGLib';
+
+import { AccountsMonitor } from './accountsMonitor.js';
+import { RoomManager } from './roomManager.js';
+import { UserStatusMonitor } from './userTracker.js';
 
 const MIN_SPINNER_TIME = 1000000;   // in microsecond
 
@@ -16,7 +25,7 @@ function _onPopoverVisibleChanged(popover) {
         context.remove_class('has-open-popup');
 }
 
-var RoomRow = GObject.registerClass({
+const RoomRow = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/room-list-row.ui',
     InternalChildren: [
         'eventBox',
@@ -279,7 +288,7 @@ class RoomRowPopover extends Gtk.Popover {
     }
 });
 
-var RoomListHeader = GObject.registerClass({
+const RoomListHeader = GObject.registerClass({
     CssName: 'row',
     Template: 'resource:///org/gnome/Polari/ui/room-list-header.ui',
     InternalChildren: [
@@ -509,7 +518,7 @@ var RoomListHeader = GObject.registerClass({
     }
 });
 
-var RoomList = GObject.registerClass(
+const RoomList = GObject.registerClass(
 class RoomList extends Gtk.ListBox {
     _init(params) {
         super._init(params);
diff --git a/src/roomManager.js b/src/roomManager.js
index a328f1ac..f07e959f 100644
--- a/src/roomManager.js
+++ b/src/roomManager.js
@@ -1,11 +1,15 @@
-/* exported RoomManager */
+export { RoomManager };
+
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
 
-const { Gio, GLib, Polari, TelepathyGLib: Tp } = imports.gi;
 const Signals = imports.signals;
 
-const { AccountsMonitor } = imports.accountsMonitor;
+import { AccountsMonitor } from './accountsMonitor.js';
 
-var RoomManager = class {
+const RoomManager = class {
     static getDefault() {
         if (!this._singleton)
             this._singleton = new RoomManager();
diff --git a/src/roomStack.js b/src/roomStack.js
index 3166dd9c..0ec32092 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -1,14 +1,18 @@
-/* exported RoomStack */
+export { RoomStack };
 
-const { Gio, GLib, GObject, Gtk, TelepathyGLib: Tp } = imports.gi;
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Tp from 'gi://TelepathyGLib';
 
-const { AccountsMonitor } = imports.accountsMonitor;
-const { ChatView } = imports.chatView;
-const { EntryArea } = imports.entryArea;
-const { MessageInfoBar } = imports.appNotifications;
-const { RoomManager } = imports.roomManager;
+import { AccountsMonitor } from './accountsMonitor.js';
+import { ChatView } from './chatView.js';
+import { EntryArea } from './entryArea.js';
+import { MessageInfoBar } from './appNotifications.js';
+import { RoomManager } from './roomManager.js';
 
-var RoomStack = GObject.registerClass({
+const RoomStack = GObject.registerClass({
     Properties: {
         'entry-area-height': GObject.ParamSpec.uint(
             'entry-area-height', 'entry-area-height', 'entry-area-height',
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 315ef3e7..698889a2 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -1,18 +1,27 @@
-/* exported ServerRoomManager ServerRoomList */
+export {
+    ServerRoomManager,
+    ServerRoomList
+};
+
+import Gdk from 'gi://Gdk';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Tp from 'gi://TelepathyGLib';
 
-const { Gdk, Gio, GLib, GObject, Gtk, TelepathyGLib: Tp } = imports.gi;
 const Signals = imports.signals;
 
-const { AccountsMonitor } = imports.accountsMonitor;
-const { RoomManager } = imports.roomManager;
-const Utils = imports.utils;
+import { AccountsMonitor } from './accountsMonitor.js';
+import { RoomManager } from './roomManager.js';
+import * as Utils from './utils.js';
 
 Gio._promisify(Tp.RoomList.prototype, 'init_async', 'init_finish');
 
 const MS_PER_IDLE = 10; // max time spend in idle
 const MS_PER_FILTER_IDLE = 5; // max time spend in idle while filtering
 
-var ServerRoomManager = class {
+const ServerRoomManager = class {
     static getDefault() {
         if (!this._singleton)
             this._singleton = new ServerRoomManager();
@@ -105,7 +114,7 @@ function _strBaseEqual(str1, str2) {
     return str1.localeCompare(str2, {}, { sensitivity: 'base' }) === 0;
 }
 
-var ServerRoomList = GObject.registerClass({
+const ServerRoomList = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/server-room-list.ui',
     InternalChildren: [
         'filterEntry',
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index f4011f33..8f85ce5d 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -1,10 +1,12 @@
-/* exported TabCompletion */
+export { TabCompletion };
 
-const { Gdk, Gtk, Pango } = imports.gi;
+import Gdk from 'gi://Gdk';
+import Gtk from 'gi://Gtk';
+import Pango from 'gi://Pango';
 
-const IrcParser = imports.ircParser;
+import * as IrcParser from './ircParser.js';
 
-var TabCompletion = class {
+const TabCompletion = class {
     constructor(entry) {
         this._entry = entry;
         this._canComplete = false;
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 751974f7..d3529b58 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -1,11 +1,15 @@
-/* exported TelepathyClient */
+export { TelepathyClient };
 
-const { Gio, GLib, GObject, Polari, TelepathyGLib: Tp } = imports.gi;
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
 
-const { AccountsMonitor } = imports.accountsMonitor;
-const { RoomManager } = imports.roomManager;
-const { UserStatusMonitor } = imports.userTracker;
-const Utils = imports.utils;
+import { AccountsMonitor } from './accountsMonitor.js';
+import { RoomManager } from './roomManager.js';
+import { UserStatusMonitor } from './userTracker.js';
+import * as Utils from './utils.js';
 
 Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
 Gio._promisify(Polari.Room.prototype,
@@ -120,7 +124,7 @@ class SASLAuthHandler {
     }
 }
 
-var TelepathyClient = GObject.registerClass(
+const TelepathyClient = GObject.registerClass(
 class TelepathyClient extends Tp.BaseClient {
     _init(params) {
         this._app = Gio.Application.get_default();
diff --git a/src/thumbnailer.js b/src/thumbnailer.js
index 5de6349f..64c1fd48 100644
--- a/src/thumbnailer.js
+++ b/src/thumbnailer.js
@@ -1,8 +1,10 @@
-imports.gi.versions.Gdk = '3.0';
-imports.gi.versions.Gtk = '3.0';
-
-const { Gdk, Gio, GLib, GObject, Gtk, WebKit2 } = imports.gi;
-const Cairo = imports.cairo;
+import Cairo from 'cairo';
+import Gdk from 'gi://Gdk?version=3.0';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk?version=3.0';
+import WebKit2 from 'gi://WebKit2';
 
 Gio._promisify(WebKit2.WebView.prototype, 'get_snapshot', 'get_snapshot_finish');
 Gio._promisify(WebKit2.WebView.prototype, 'run_javascript', 'run_javascript_finish');
diff --git a/src/urlPreview.js b/src/urlPreview.js
index 33b7a24e..4de26fe6 100644
--- a/src/urlPreview.js
+++ b/src/urlPreview.js
@@ -1,5 +1,10 @@
-/* exported URLPreview */
-const { Gio, GLib, GObject, Gtk, Pango } = imports.gi;
+export { URLPreview };
+
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Pango from 'gi://Pango';
 
 Gio._promisify(Gio._LocalFilePrototype, 'query_info_async', 'query_info_finish');
 Gio._promisify(Gio.Subprocess.prototype, 'wait_async', 'wait_finish');
@@ -65,7 +70,7 @@ class Thumbnailer {
     async _generateThumbnail(data) {
         let { filename, uri } = data;
         this._subProc = Gio.Subprocess.new(
-            ['gjs', `${pkg.pkgdatadir}/thumbnailer.js`, uri, filename],
+            ['gjs', '--module', `${pkg.pkgdatadir}/thumbnailer.js`, uri, filename],
             Gio.SubprocessFlags.NONE);
         try {
             await this._subProc.wait_async(null);
@@ -95,7 +100,7 @@ class Thumbnailer {
     }
 }
 
-var URLPreview = GObject.registerClass({
+const URLPreview = GObject.registerClass({
     Properties: {
         'uri': GObject.ParamSpec.string(
             'uri', 'uri', 'uri',
diff --git a/src/userList.js b/src/userList.js
index 2db6b704..698a1bd8 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -1,15 +1,24 @@
-/* exported UserList UserListPopover UserDetails UserPopover */
-
-const {
-    Gio, GLib, GObject, Gtk, Pango, Polari, TelepathyGLib: Tp,
-} = imports.gi;
-
-const Utils = imports.utils;
+export {
+    UserList,
+    UserListPopover,
+    UserDetails,
+    UserPopover
+};
+
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Gtk from 'gi://Gtk';
+import Pango from 'gi://Pango';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
+
+import * as Utils from './utils.js';
 
 const FILTER_ENTRY_THRESHOLD = 8;
 const MAX_USERS_WIDTH_CHARS = 17;
 
-var UserListPopover = GObject.registerClass(
+const UserListPopover = GObject.registerClass(
 class UserListPopover extends Gtk.Popover {
     _init(params) {
         super._init(params);
@@ -112,7 +121,7 @@ class UserListPopover extends Gtk.Popover {
     }
 });
 
-var UserDetails = GObject.registerClass({
+const UserDetails = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/user-details.ui',
     InternalChildren: [
         'spinnerBox',
@@ -313,7 +322,7 @@ var UserDetails = GObject.registerClass({
     }
 });
 
-var UserPopover = GObject.registerClass({
+const UserPopover = GObject.registerClass({
     Template: 'resource:///org/gnome/Polari/ui/user-popover.ui',
     InternalChildren: [
         'nickLabel',
@@ -545,7 +554,7 @@ class UserListRow extends Gtk.ListBoxRow {
     }
 });
 
-var UserList = GObject.registerClass(
+const UserList = GObject.registerClass(
 class UserList extends Gtk.ScrolledWindow {
     _init(room) {
         super._init({
diff --git a/src/userTracker.js b/src/userTracker.js
index 4f6761aa..d8a9ea00 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -1,12 +1,16 @@
-/* exported UserStatusMonitor */
+export { UserStatusMonitor };
 
-const { Gio, GLib, GObject, Polari, TelepathyGLib: Tp } = imports.gi;
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import GObject from 'gi://GObject';
+import Polari from 'gi://Polari';
+import Tp from 'gi://TelepathyGLib';
 
-const { AccountsMonitor } = imports.accountsMonitor;
-const { RoomManager } = imports.roomManager;
-const Utils = imports.utils;
+import { AccountsMonitor } from './accountsMonitor.js';
+import { RoomManager } from './roomManager.js';
+import * as Utils from './utils.js';
 
-var UserStatusMonitor = class {
+const UserStatusMonitor = class {
     static getDefault() {
         if (!this._singleton)
             this._singleton = new UserStatusMonitor();
diff --git a/src/utils.js b/src/utils.js
index 1d197134..c74c332c 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -1,10 +1,3 @@
-/* exported isFlatpakSandbox touchFile needsOnetimeAction getTpEventTime
-            findUrls findChannels openURL updateTerms gpaste imgurPaste
-            storeAccountPassword storeIdentifyPassword
-            lookupAccountPassword lookupIdentifyPassword
-            clearAccountPassword clearIdentifyPassword
-            updateTerms gpaste imgurPaste formatTimePassed*/
-
 /*
  * Copyright (c) 2011 Red Hat, Inc.
  *
@@ -27,9 +20,35 @@
  *
  */
 
-const { Gdk, Gio, GLib, Gtk, Secret, Soup, TelepathyGLib: Tp }  = imports.gi;
-
-const AppNotifications = imports.appNotifications;
+export {
+    isFlatpakSandbox,
+    touchFile,
+    needsOnetimeAction,
+    getTpEventTime,
+    findUrls,
+    findChannels,
+    openURL,
+    updateTerms,
+    gpaste,
+    imgurPaste,
+    storeAccountPassword,
+    storeIdentifyPassword,
+    lookupAccountPassword,
+    lookupIdentifyPassword,
+    clearAccountPassword,
+    clearIdentifyPassword,
+    formatTimePassed
+};
+
+import Gdk from 'gi://Gdk';
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import Gtk from 'gi://Gtk';
+import Secret from 'gi://Secret';
+import Soup from 'gi://Soup';
+import Tp from 'gi://TelepathyGLib';
+
+import * as AppNotifications from './appNotifications.js';
 
 Gio._promisify(Secret, 'password_store', 'password_store_finish');
 Gio._promisify(Secret, 'password_lookup', 'password_lookup_finish');


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