Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
chore: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Feb 19, 2024
1 parent 1201c50 commit 23c5de9
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 144 deletions.
4 changes: 2 additions & 2 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ export class Application extends Adw.Application {
this.present_main_window();
}

vfunc_open(files: Gio.FilePrototype[], hint: string): void {
vfunc_open(files: Gio.FilePrototype[]): void {
this.present_main_window();

const window = this.get_active_window();

if (window && window instanceof Window && files.length > 0) {
window.load_file(files[0]);
void window.load_file(files[0]);
}
}
}
7 changes: 2 additions & 5 deletions src/drag-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export class APDragOverlay extends Adw.Bin {
this._notify_current_drop_cb.bind(this),
);

this._drop_target.connect(
"drop",
this._drop_target_drop_cb.bind(this),
);
this._drop_target.connect("drop", this._drop_target_drop_cb.bind(this));

this.add_controller(this._drop_target);
}
Expand Down Expand Up @@ -75,7 +72,7 @@ export class APDragOverlay extends Adw.Bin {
return false;
}

this.get_window().load_file(file);
void this.get_window().load_file(file);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class APErrorState extends Adw.Bin {
this._statusPage.set_description(message);
}

show_error(title: string, error: any) {
show_error(title: string, error: unknown) {
this._statusPage.title = title;

if (error instanceof Error) {
Expand All @@ -39,7 +39,7 @@ export class APErrorState extends Adw.Bin {
} else {
console.error("error: ", error);
this.show_message(
error ? error.toString() : _("An unknown error happened"),
error ? (error as Error).toString() : _("An unknown error happened"),
);
}
}
Expand Down
45 changes: 22 additions & 23 deletions src/mpris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ const MPRIS_XML = `
export class DBusInterface {
connection!: Gio.DBusConnection;

constructor(private name: string, private path: string) {
constructor(
private name: string,
private path: string,
) {
Gio.bus_get(Gio.BusType.SESSION, null)
.then(this.got_bus.bind(this))
.catch((e: GLib.Error) => {
Expand Down Expand Up @@ -160,7 +163,7 @@ export class DBusInterface {
parameters: GLib.Variant,
invocation: Gio.DBusMethodInvocation,
) {
const args = parameters.unpack() as any[];
const args = parameters.unpack() as unknown[];

this.method_inargs.get(method_name)!.forEach((sig, i) => {
if (sig === "h") {
Expand All @@ -174,8 +177,10 @@ export class DBusInterface {

let result;

type Method = (...args: unknown[]) => unknown;

try {
result = (this[method_snake_name as keyof this] as any)(...args);
result = (this[method_snake_name as keyof this] as Method)(...args);
} catch (error) {
invocation.return_dbus_error(
interface_name,
Expand All @@ -196,7 +201,7 @@ export class DBusInterface {
}
}

_dbus_emit_signal(signal_name: string, values: Record<string, any>) {
_dbus_emit_signal(signal_name: string, values: Record<string, unknown>) {
if (this.signals.size === 0) return;

const signal = this.signals.get(signal_name)!;
Expand All @@ -208,6 +213,8 @@ export class DBusInterface {
parameters.push(GLib.Variant.new(signature, value));
}

// TODO: the type is incorrect
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const variant = GLib.Variant.new_tuple(parameters as any);

this.connection.emit_signal(
Expand Down Expand Up @@ -259,7 +266,7 @@ export class MPRIS extends DBusInterface {

this.stream.connect("notify::seeking", () => {
if (!this.stream.seeking) {
this._on_seek_finished(this as any, this.stream.timestamp);
this._on_seek_finished(this, this.stream.timestamp);
}
});
}
Expand Down Expand Up @@ -340,7 +347,7 @@ export class MPRIS extends DBusInterface {
);
}

private _on_seek_finished(_: Gtk.Widget, position: number) {
private _on_seek_finished(_: unknown, position: number) {
this._seeked(Math.trunc(position));
}

Expand Down Expand Up @@ -437,7 +444,7 @@ export class MPRIS extends DBusInterface {
*
* Not implemented
*/
open_uri(_uri: string) {
open_uri() {
return;
}

Expand Down Expand Up @@ -471,7 +478,7 @@ export class MPRIS extends DBusInterface {
const iface = interface_name.get_string()[0];

switch (iface) {
case this.MEDIA_PLAYER2_IFACE:
case this.MEDIA_PLAYER2_IFACE: {
const application_id = this.app.get_application_id() ?? "";

return {
Expand All @@ -485,7 +492,8 @@ export class MPRIS extends DBusInterface {
SupportedUriSchemes: GLib.Variant.new_strv([]),
SupportedMimeTypes: GLib.Variant.new_strv([]),
};
case this.MEDIA_PLAYER2_PLAYER_IFACE:
}
case this.MEDIA_PLAYER2_PLAYER_IFACE: {
const position_msecond = Math.trunc(this.stream.timestamp);
const playback_status = this._get_playback_status();

Expand All @@ -505,6 +513,7 @@ export class MPRIS extends DBusInterface {
CanSeek: GLib.Variant.new_boolean(true),
CanControl: GLib.Variant.new_boolean(true),
};
}
case "org.freedesktop.DBus.Properties":
return {};
case "org.freedesktop.DBus.Introspectable":
Expand Down Expand Up @@ -550,14 +559,16 @@ export class MPRIS extends DBusInterface {
break;
default:
console.warn(
`MPRIS can not set, as it does not implement ${interface_name}`,
`MPRIS can not set, as it does not implement ${
interface_name.get_string()[0]
}`,
);
}
}

_properties_changed(
interface_name: string,
changed_properties: Record<string, GLib.Variant<any>>,
changed_properties: Record<string, GLib.Variant>,
invalidated_properties: string[],
) {
this._dbus_emit_signal("PropertiesChanged", {
Expand All @@ -571,15 +582,3 @@ export class MPRIS extends DBusInterface {
return MPRIS_XML;
}
}

function hex_encode(string: string) {
var hex, i;

var result = "";
for (i = 0; i < string.length; i++) {
hex = string.charCodeAt(i).toString(16);
result += ("000" + hex).slice(-4);
}

return result;
}
11 changes: 4 additions & 7 deletions src/playback-rate-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export class APPlaybackRateButton extends Adw.Bin {
{
GTypeName: "APPlaybackRateButton",
Template: "resource:///com/vixalien/decibels/playback-rate-button.ui",
InternalChildren: [
"adjustment",
"label"
],
InternalChildren: ["adjustment", "label"],
Properties: {},
},
this,
Expand All @@ -39,7 +36,7 @@ export class APPlaybackRateButton extends Adw.Bin {
GObject.BindingFlags.SYNC_CREATE,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"rate",
this._label,
Expand All @@ -52,14 +49,14 @@ export class APPlaybackRateButton extends Adw.Bin {
null,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"rate",
this._label,
"visible",
GObject.BindingFlags.SYNC_CREATE,
(_binding, from: number) => {
const rounded = Math.round(from * 10) / 10
const rounded = Math.round(from * 10) / 10;
return [true, rounded !== 1];
},
null,
Expand Down
37 changes: 10 additions & 27 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export class APPlayerState extends Adw.Bin {
"waveform",
"scale",
],
Children: [
"headerbar",
],
Children: ["headerbar"],
},
this,
);
Expand All @@ -63,7 +61,7 @@ export class APPlayerState extends Adw.Bin {
GObject.BindingFlags.SYNC_CREATE,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"duration",
this._duration_label,
Expand All @@ -76,13 +74,13 @@ export class APPlayerState extends Adw.Bin {
null,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"timestamp",
this._scale_adjustment,
"value",
GObject.BindingFlags.SYNC_CREATE,
(_binding, from: number) => {
() => {
if ((this._scale.get_state_flags() & Gtk.StateFlags.ACTIVE) != 0) {
return [false, null];
}
Expand All @@ -92,7 +90,7 @@ export class APPlayerState extends Adw.Bin {
null,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"timestamp",
this._timestamp_label,
Expand All @@ -111,24 +109,19 @@ export class APPlayerState extends Adw.Bin {
GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"playing",
this._playback_image,
"icon-name",
GObject.BindingFlags.SYNC_CREATE,
(_binding, from: boolean) => {
return [
true,
from
? "pause-symbolic"
: "play-symbolic",
];
return [true, from ? "pause-symbolic" : "play-symbolic"];
},
null,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"playing",
this._playback_button,
Expand All @@ -140,7 +133,7 @@ export class APPlayerState extends Adw.Bin {
null,
);

// @ts-ignore GObject.BindingTransformFunc return arguments are not correctly typed
// @ts-expect-error GObject.BindingTransformFunc return arguments are not correctly typed
window.stream.bind_property_full(
"timestamp",
this._waveform,
Expand Down Expand Up @@ -191,11 +184,7 @@ export class APPlayerState extends Adw.Bin {
});
}

private scale_change_value_cb(
_scale: Gtk.Scale,
_scroll: Gtk.ScrollType,
_value: number,
) {
private scale_change_value_cb() {
const window = this.get_root() as Window;
const stream = window?.stream;

Expand Down Expand Up @@ -229,8 +218,6 @@ export class APPlayerState extends Adw.Bin {
private key_pressed_cb(
_controller: Gtk.EventControllerKey,
keyval: number,
_keycode: number,
_modifier: Gdk.ModifierType,
): boolean {
const window = this.get_root() as Window;
const stream = window?.stream;
Expand Down Expand Up @@ -272,10 +259,6 @@ export class APPlayerState extends Adw.Bin {
}
}

function get_window() {
return (Gtk.Application.get_default() as Gtk.Application).get_active_window();
}

function seconds_to_string(seconds: number) {
// show the duration in the format "mm:ss"
// show hours if the duration is longer than an hour
Expand Down
Loading

0 comments on commit 23c5de9

Please sign in to comment.