diff --git a/src/app.ts b/src/app.ts index bb908e9..028c672 100644 --- a/src/app.ts +++ b/src/app.ts @@ -146,7 +146,7 @@ export default class App extends Gtk.Application { getWindow(name: string) { const w = this._windows.get(name); if (!w) - console.error(`There is no window named ${name}`); + console.error(Error(`There is no window named ${name}`)); return w; } @@ -156,7 +156,7 @@ export default class App extends Gtk.Application { const win = this._windows.get(name); if (!win) { - console.error('There is no window named ' + name); + console.error(Error('There is no window named ' + name)); return; } @@ -166,8 +166,8 @@ export default class App extends Gtk.Application { addWindow(w: Gtk.Window) { if (!(w instanceof Gtk.Window)) { - console.error(`${w} is not an instanceof Gtk.Window, ` + - ` but it is of type ${typeof w}`); + console.error(Error(`${w} is not an instanceof Gtk.Window, ` + + ` but it is of type ${typeof w}`)); return; } @@ -175,7 +175,7 @@ export default class App extends Gtk.Application { () => this.emit('window-toggled', w.name, w.visible)); if (this._windows.has(w.name)) { - console.error('There is already a window named' + w.name); + console.error(Error('There is already a window named' + w.name)); this.quit(); return; } @@ -215,7 +215,7 @@ export default class App extends Gtk.Application { this.emit('config-parsed'); } catch (err) { - logError(err as Error); + console.error(err as Error); } } @@ -253,7 +253,7 @@ export default class App extends Gtk.Application { } else { print(`${out}`); } }) - .catch(logError); + .catch(console.error); } ToggleWindow(name: string) { diff --git a/src/service/applications.ts b/src/service/applications.ts index 4383646..8acee48 100644 --- a/src/service/applications.ts +++ b/src/service/applications.ts @@ -112,7 +112,7 @@ class ApplicationsService extends Service { ensureDirectory(APPS_CACHE_DIR); const json = JSON.stringify(this._frequents, null, 2); - writeFile(json, CACHE_FILE).catch(logError); + writeFile(json, CACHE_FILE).catch(console.error); this.notify('frequents'); this.emit('changed'); } diff --git a/src/service/bluetooth.ts b/src/service/bluetooth.ts index aa8c024..a5717a1 100644 --- a/src/service/bluetooth.ts +++ b/src/service/bluetooth.ts @@ -172,7 +172,7 @@ class BluetoothService extends Service { callback(s); this.changed('connected-devices'); } catch (error) { - logError(error as Error); + console.error(error as Error); callback(false); } }, diff --git a/src/service/hyprland.ts b/src/service/hyprland.ts index 6cbc952..c657de5 100644 --- a/src/service/hyprland.ts +++ b/src/service/hyprland.ts @@ -174,7 +174,7 @@ class HyprlandService extends Service { }); this.notify('monitors'); } catch (error) { - logError(error as Error); + console.error(error as Error); } } @@ -188,7 +188,7 @@ class HyprlandService extends Service { }); this.notify('workspaces'); } catch (error) { - logError(error as Error); + console.error(error as Error); } } @@ -202,7 +202,7 @@ class HyprlandService extends Service { }); this.notify('clients'); } catch (error) { - logError(error as Error); + console.error(error as Error); } } @@ -298,7 +298,7 @@ class HyprlandService extends Service { break; } } catch (error) { - logError(error as Error); + console.error(error as Error); } this.emit('changed'); diff --git a/src/service/mpris.ts b/src/service/mpris.ts index 757b08a..42c4e15 100644 --- a/src/service/mpris.ts +++ b/src/service/mpris.ts @@ -204,8 +204,9 @@ class MprisPlayer extends Service { source.copy_finish(result); this.changed('cover-path'); } - catch (e) { - logError(e as Error, `failed to cache ${this._coverPath}`); + catch (err) { + console.error(`failed to cache ${this._coverPath}`); + console.error(err as Error); } }, ); @@ -245,12 +246,12 @@ class MprisPlayer extends Service { this.emit('position', time); } - playPause() { this._playerProxy.PlayPauseAsync().catch(logError); } - play() { this._playerProxy.PlayAsync().catch(logError); } - stop() { this._playerProxy.StopAsync().catch(logError); } + playPause() { this._playerProxy.PlayPauseAsync().catch(console.error); } + play() { this._playerProxy.PlayAsync().catch(console.error); } + stop() { this._playerProxy.StopAsync().catch(console.error); } - next() { this._playerProxy.NextAsync().catch(logError); } - previous() { this._playerProxy.PreviousAsync().catch(logError); } + next() { this._playerProxy.NextAsync().catch(console.error); } + previous() { this._playerProxy.PreviousAsync().catch(console.error); } shuffle() { this._playerProxy.Shuffle = !this._playerProxy.Shuffle; } loop() { diff --git a/src/service/network.ts b/src/service/network.ts index 983e77e..a41c82d 100644 --- a/src/service/network.ts +++ b/src/service/network.ts @@ -238,7 +238,7 @@ class NetworkService extends Service { this._clientReady(); } catch (e) { - logError(e as Error); + console.error(e as Error); } }); } diff --git a/src/service/notifications.ts b/src/service/notifications.ts index d48ef4d..9e10025 100644 --- a/src/service/notifications.ts +++ b/src/service/notifications.ts @@ -354,7 +354,7 @@ class NotificationsService extends Service { private _cache() { ensureDirectory(NOTIFICATIONS_CACHE_PATH); const arr = Array.from(this._notifications.values()).map(n => n.toJson()); - writeFile(JSON.stringify(arr, null, 2), CACHE_FILE).catch(logError); + writeFile(JSON.stringify(arr, null, 2), CACHE_FILE).catch(console.error); } } diff --git a/src/utils.ts b/src/utils.ts index 4f8165a..af4613a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,7 +4,6 @@ import GLib from 'gi://GLib'; import GObject from 'gi://GObject'; import { Command } from './widgets/constructor.js'; - export const USER = GLib.get_user_name(); export const CACHE_DIR = `${GLib.get_user_cache_dir()}/${pkg.name.split('.').pop()}`; @@ -63,7 +62,7 @@ export function loadInterfaceXML(iface: string) { const [, bytes] = f.load_contents(null); return new TextDecoder().decode(bytes); } catch (e) { - logError(e as Error); + console.error(e as Error); return null; } } @@ -73,8 +72,7 @@ export function bulkConnect( service: GObject.Object, list: [ event: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (...args: any[]) => void + callback: (...args: unknown[]) => void ][], ) { const ids = []; @@ -212,7 +210,7 @@ export function exec(cmd: string) { export function subprocess( cmd: string | string[], callback: (out: string) => void, - onError = logError, + onError = console.error, bind?: Gtk.Widget, ) { try { diff --git a/src/variable.ts b/src/variable.ts index a468ff0..6435276 100644 --- a/src/variable.ts +++ b/src/variable.ts @@ -50,16 +50,16 @@ class AgsVariable extends GObject.Object { startPoll() { if (!this._poll) - return console.error(`${this} has no poll defined`); + return console.error(Error(`${this} has no poll defined`)); if (this._interval) - return console.error(`${this} is already polling`); + return console.error(Error(`${this} is already polling`)); const [time, cmd, transform = out => out] = this._poll; if (Array.isArray(cmd) || typeof cmd === 'string') { this._interval = interval(time, () => execAsync(cmd) .then(out => this.setValue(transform(out))) - .catch(logError)); + .catch(console.error)); } if (typeof cmd === 'function') this._interval = interval(time, () => this.setValue(cmd())); @@ -70,16 +70,16 @@ class AgsVariable extends GObject.Object { GLib.source_remove(this._interval); this._interval = 0; } else { - console.error(`${this} has no poll running`); + console.error(Error(`${this} has no poll running`)); } } startListen() { if (!this._listen) - return console.error(`${this} has no listen defined`); + return console.error(Error(`${this} has no listen defined`)); if (this._subprocess) - return console.error(`${this} is already listening`); + return console.error(Error(`${this} is already listening`)); let cmd: string | string[]; const transform = typeof this._listen[1] === 'function' @@ -99,7 +99,7 @@ class AgsVariable extends GObject.Object { cmd = this._listen[0]; else - return console.error(`${this._listen} is not a valid type for Variable.listen`); + return console.error(Error(`${this._listen} is not a valid type for Variable.listen`)); this._subprocess = subprocess(cmd, out => this.setValue(transform(out))); } @@ -109,7 +109,7 @@ class AgsVariable extends GObject.Object { this._subprocess.force_exit(); this._subprocess = null; } else { - console.error(`${this} has no listen running`); + console.error(Error(`${this} has no listen running`)); } } diff --git a/src/widget.ts b/src/widget.ts index e2f7ca8..3b4e5ed 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -40,7 +40,7 @@ export const Scrollable = (args: object) => constructor(AgsScrollable, args); export const Slider = (args: object) => constructor(AgsSlider, args); export const Stack = (args: object) => constructor(AgsStack, args); -// so it is still in global scope through ags.Widget +// so they are still accessible when importing only Widget Widget.Widget = Widget; Widget.Box = Box; Widget.Button = Button; diff --git a/src/widgets/constructor.ts b/src/widgets/constructor.ts index 3709432..9fb06a6 100644 --- a/src/widgets/constructor.ts +++ b/src/widgets/constructor.ts @@ -97,7 +97,7 @@ function parseCommon(widget: Gtk.Widget, { if (binds) { binds.forEach(([prop, obj, objProp = 'value', transform = out => out]) => { if (!prop || !obj) { - logError(new Error('missing arguments to binds')); + console.error(Error('missing arguments to binds')); return; } @@ -110,7 +110,7 @@ function parseCommon(widget: Gtk.Widget, { if (connections) { connections.forEach(([s, callback, event]) => { if (!s || !callback) { - logError(new Error('missing arguments to connections')); + console.error(Error('missing arguments to connections')); return; } @@ -130,7 +130,7 @@ function parseCommon(widget: Gtk.Widget, { connect(s, widget, callback, event); else - logError(new Error(`${s} is not connectable`)); + console.error(Error(`${s} is not connectable`)); }); } diff --git a/src/widgets/icon.ts b/src/widgets/icon.ts index d9c7382..dc72862 100644 --- a/src/widgets/icon.ts +++ b/src/widgets/icon.ts @@ -80,7 +80,7 @@ export default class AgsIcon extends Gtk.Image { } } else { - logError(new Error(`expected Pixbuf or string for icon, but got ${typeof icon}`)); + console.error(Error(`expected Pixbuf or string for icon, but got ${typeof icon}`)); } } diff --git a/src/widgets/label.ts b/src/widgets/label.ts index 8a70594..1b8b255 100644 --- a/src/widgets/label.ts +++ b/src/widgets/label.ts @@ -32,7 +32,7 @@ export default class AgsLabel extends Gtk.Label { if (e instanceof GLib.MarkupError) label = GLib.markup_escape_text(label, -1); else - logError(e as Error); + console.error(e as Error); } } super.label = label; diff --git a/types/ambient.d.ts b/types/ambient.d.ts index e6858ac..9842c2d 100644 --- a/types/ambient.d.ts +++ b/types/ambient.d.ts @@ -1,7 +1,4 @@ declare function print(...args: any[]): void; -declare function log(obj: object, others?: object[]): void; -declare function log(msg: string, subsitutions?: any[]): void; -declare function logError(err: Error, msg?: string): void; declare const pkg: { version: string; @@ -17,6 +14,8 @@ declare const imports: { declare module console { export function error(obj: object, others?: object[]): void; export function error(msg: string, subsitutions?: any[]): void; + export function log(obj: object, others?: object[]): void; + export function log(msg: string, subsitutions?: any[]): void; } declare interface String {