Skip to content

Commit

Permalink
Fix dynamic import troubles, daemon init
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Sep 24, 2023
1 parent b32bf54 commit e53e7c0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/service/components/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ let EBookContacts = null;
let EDataServer = null;

try {
EBook = await import('gi://EBook');
EBookContacts = await import('gi://EBookContacts');
EDataServer = await import('gi://EDataServer');
EBook = (await import('gi://EBook')).default;
EBookContacts = (await import('gi://EBookContacts')).default;
EDataServer = (await import('gi://EDataServer')).default;
} catch (e) {
HAVE_EDS = false;
}
Expand Down
12 changes: 9 additions & 3 deletions src/service/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const Default = new Map();
// Load all components using dynamic import
const components = {};

const dir = Gio.File.new_for_uri(import.meta.url).get_parent().resolve_relative_path('components');
// Promisify because prefs also imports this file
Gio._promisify(Gio.File.prototype, 'enumerate_children_async');
Gio._promisify(Gio.FileEnumerator.prototype, 'next_files_async');

const dir = Gio.File.new_for_uri(import.meta.url).get_parent();
const iter = await dir.enumerate_children_async(
Gio.FILE_ATTRIBUTE_STANDARD_NAME,
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
Expand All @@ -24,8 +28,10 @@ iter.close_async(GLib.PRIORITY_DEFAULT, null, null);

for (let i = 0; i < infos.length; i++) {
const info = infos[i];
const name = info.get_name();
components[name] = await import(`./components/${name}.js`);
const name = info.get_name().replace(/\.js$/, '');
if (name === 'index')
continue;
components[name] = await import(`./${name}.js`);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/service/components/pulseaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import GIRepository from 'gi://GIRepository';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gvc from 'gi://Gvc';

import Config from '../../config.js';

Expand All @@ -17,6 +16,8 @@ const typelibDir = GLib.build_filenamev([Config.GNOME_SHELL_LIBDIR, 'gnome-shell
GIRepository.Repository.prepend_search_path(typelibDir);
GIRepository.Repository.prepend_library_path(typelibDir);

const Gvc = (await import('gi://Gvc')).default;


/**
* Extend Gvc.MixerStream with a property for returning a user-visible name
Expand Down
4 changes: 2 additions & 2 deletions src/service/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import 'gi://Pango?version=1.0';

import system from 'system';

import './utils/setup.js';
import Config from '../config.js';
import Manager from './manager.js';
import ServiceUI from './ui/service.js';
import './utils/setup.js';
import * as ServiceUI from './ui/service.js';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/service/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ iter.close_async(GLib.PRIORITY_DEFAULT, null, null);

for (let i = 0; i < infos.length; i++) {
const info = infos[i];
const name = info.get_name();
const name = info.get_name().replace(/\.js$/, '');
backends[name] = await import(`./backends/${name}.js`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/plugins/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Contacts from '../components/contacts.js';
let EBookContacts;

try {
EBookContacts = await import('gi://EBookContacts');
EBookContacts = (await import('gi://EBookContacts')).default;
} catch (e) {
EBookContacts = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/service/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ iter.close_async(GLib.PRIORITY_DEFAULT, null, null);

for (let i = 0; i < infos.length; i++) {
const info = infos[i];
const name = info.get_name();
if (name === 'index.js')
const name = info.get_name().replace(/\.js$/, '');
if (name === 'index')
continue;
plugins[name] = await import(`./${name}.js`);
}
Expand Down
9 changes: 6 additions & 3 deletions src/service/utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import setup, {setupGettext} from '../../utils/setup.js';

// Promise Wrappers
try {
const EBook = await import('gi://EBook');
const EDataServer = await import('gi://EDataServer');
const EBook = (await import('gi://EBook')).default;
const EDataServer = (await import('gi://EDataServer')).default;

Gio._promisify(EBook.BookClient, 'connect');
Gio._promisify(EBook.BookClient.prototype, 'get_view');
Expand Down Expand Up @@ -60,7 +60,10 @@ Config.RUNTIMEDIR = GLib.build_filenamev([GLib.get_user_runtime_dir(), 'gsconnec


// Bootstrap
setup(Config.PACKAGE_DATADIR);
const utilsFolder = GLib.path_get_dirname(GLib.filename_from_uri(import.meta.url)[0]);
const serviceFolder = GLib.path_get_dirname(utilsFolder);
const extensionFolder = GLib.path_get_dirname(serviceFolder);
setup(extensionFolder);
setupGettext();

if (Config.IS_USER) {
Expand Down

0 comments on commit e53e7c0

Please sign in to comment.