Skip to content

Commit

Permalink
WIP: Reorganise setup code to fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Sep 30, 2023
1 parent f36ec7c commit 5749e29
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
7 changes: 5 additions & 2 deletions src/gsconnect-preferences
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ import Gtk from 'gi://Gtk?version=3.0';

import system from 'system';

import {Window} from './preferences/service.js';
import setup, {setupGettext} from './utils/setup.js';
import Config from './config.js';


// Bootstrap
setup(GLib.path_get_dirname(GLib.filename_from_uri(import.meta.url)));
setup(GLib.path_get_dirname(GLib.filename_from_uri(import.meta.url)[0]));
setupGettext();


// Postpone remaining imports until after setup
const {Window} = await import('./preferences/service.js');


/**
* Class representing the GSConnect service daemon.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/service/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ for (let i = 0; i < infos.length; i++) {
const name = info.get_name().replace(/\.js$/, '');
if (name === 'index')
continue;
components[name] = await import(`./${name}.js`);
try {
components[name] = await import(`./${name}.js`);
} catch (e) {}
}

/**
Expand Down
82 changes: 41 additions & 41 deletions src/service/utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,6 @@ import Config from '../../config.js';
import setup, {setupGettext} from '../../utils/setup.js';


// Promise Wrappers
try {
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');
Gio._promisify(EBook.BookClient.prototype, 'get_contacts');
Gio._promisify(EDataServer.SourceRegistry, 'new');
} finally {
// Silence import errors
}

Gio._promisify(Gio.AsyncInitable.prototype, 'init_async');
Gio._promisify(Gio.DBusConnection.prototype, 'call');
Gio._promisify(Gio.DBusProxy.prototype, 'call');
Gio._promisify(Gio.DataInputStream.prototype, 'read_line_async',
'read_line_finish_utf8');
Gio._promisify(Gio.File.prototype, 'delete_async');
Gio._promisify(Gio.File.prototype, 'enumerate_children_async');
Gio._promisify(Gio.File.prototype, 'load_contents_async');
Gio._promisify(Gio.File.prototype, 'mount_enclosing_volume');
Gio._promisify(Gio.File.prototype, 'query_info_async');
Gio._promisify(Gio.File.prototype, 'read_async');
Gio._promisify(Gio.File.prototype, 'replace_async');
Gio._promisify(Gio.File.prototype, 'replace_contents_bytes_async',
'replace_contents_finish');
Gio._promisify(Gio.FileEnumerator.prototype, 'next_files_async');
Gio._promisify(Gio.Mount.prototype, 'unmount_with_operation');
Gio._promisify(Gio.InputStream.prototype, 'close_async');
Gio._promisify(Gio.OutputStream.prototype, 'close_async');
Gio._promisify(Gio.OutputStream.prototype, 'splice_async');
Gio._promisify(Gio.OutputStream.prototype, 'write_all_async');
Gio._promisify(Gio.SocketClient.prototype, 'connect_async');
Gio._promisify(Gio.SocketListener.prototype, 'accept_async');
Gio._promisify(Gio.Subprocess.prototype, 'communicate_utf8_async');
Gio._promisify(Gio.Subprocess.prototype, 'wait_check_async');
Gio._promisify(Gio.TlsConnection.prototype, 'handshake_async');
Gio._promisify(Gio.DtlsConnection.prototype, 'handshake_async');


// User Directories
Config.CACHEDIR = GLib.build_filenamev([GLib.get_user_cache_dir(), 'gsconnect']);
Config.CONFIGDIR = GLib.build_filenamev([GLib.get_user_config_dir(), 'gsconnect']);
Expand Down Expand Up @@ -103,6 +62,47 @@ for (const path of [Config.CACHEDIR, Config.CONFIGDIR, Config.RUNTIMEDIR])
GLib.mkdir_with_parents(path, 0o755);


// Promise Wrappers
try {
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');
Gio._promisify(EBook.BookClient.prototype, 'get_contacts');
Gio._promisify(EDataServer.SourceRegistry, 'new');
} finally {
// Silence import errors
}

Gio._promisify(Gio.AsyncInitable.prototype, 'init_async');
Gio._promisify(Gio.DBusConnection.prototype, 'call');
Gio._promisify(Gio.DBusProxy.prototype, 'call');
Gio._promisify(Gio.DataInputStream.prototype, 'read_line_async',
'read_line_finish_utf8');
Gio._promisify(Gio.File.prototype, 'delete_async');
Gio._promisify(Gio.File.prototype, 'enumerate_children_async');
Gio._promisify(Gio.File.prototype, 'load_contents_async');
Gio._promisify(Gio.File.prototype, 'mount_enclosing_volume');
Gio._promisify(Gio.File.prototype, 'query_info_async');
Gio._promisify(Gio.File.prototype, 'read_async');
Gio._promisify(Gio.File.prototype, 'replace_async');
Gio._promisify(Gio.File.prototype, 'replace_contents_bytes_async',
'replace_contents_finish');
Gio._promisify(Gio.FileEnumerator.prototype, 'next_files_async');
Gio._promisify(Gio.Mount.prototype, 'unmount_with_operation');
Gio._promisify(Gio.InputStream.prototype, 'close_async');
Gio._promisify(Gio.OutputStream.prototype, 'close_async');
Gio._promisify(Gio.OutputStream.prototype, 'splice_async');
Gio._promisify(Gio.OutputStream.prototype, 'write_all_async');
Gio._promisify(Gio.SocketClient.prototype, 'connect_async');
Gio._promisify(Gio.SocketListener.prototype, 'accept_async');
Gio._promisify(Gio.Subprocess.prototype, 'communicate_utf8_async');
Gio._promisify(Gio.Subprocess.prototype, 'wait_check_async');
Gio._promisify(Gio.TlsConnection.prototype, 'handshake_async');
Gio._promisify(Gio.DtlsConnection.prototype, 'handshake_async');


/**
* Check if we're in a Wayland session (mostly for input synthesis)
* https://wiki.gnome.org/Accessibility/Wayland#Bugs.2FIssues_We_Must_Address
Expand Down

0 comments on commit 5749e29

Please sign in to comment.