Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace binds for methods with lambda methods #19

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions ts/bridge/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Greeter {
logger.debug("LightDM API connected");
}

_connect_signals(): void {
_connect_signals = (): void => {
LightDMGreeter.connect("authentication-complete", () => {
this._emit_signal("authentication-complete");
});
Expand All @@ -94,9 +94,9 @@ export class Greeter {
LightDMGreeter.connect("reset", () => {
this._emit_signal("reset");
});
}
};

_emit_signal(signal: string, ...args: unknown[]): void {
_emit_signal = (signal: string, ...args: unknown[]): void => {
//console.log("SIGNAL EMITTED", signal, args)
for (const win of browser.windows) {
win.window.webContents.send(
Expand All @@ -105,7 +105,7 @@ export class Greeter {
...args
);
}
}
};

public static getInstance(config: web_greeter_config): Greeter {
return this._instance || (this._instance = new this(config));
Expand Down Expand Up @@ -397,130 +397,130 @@ export class Greeter {
* Starts the authentication procedure for a user.
* @param {string|null} username A username or "null" to prompt for a username.
*/
authenticate(username: string | null): boolean {
authenticate = (username: string | null): boolean => {
return LightDMGreeter.authenticate(username);
}
};

/**
* Starts the authentication procedure for the guest user.
*/
authenticate_as_guest(): boolean {
authenticate_as_guest = (): boolean => {
return LightDMGreeter.authenticateAsGuest();
}
};

/**
* Set the brightness to quantity
* @param {number} quantity The quantity to set
* @deprecated Use `brightness_set`
*/
brightnessSet(quantity: number): void {
brightnessSet = (quantity: number): void => {
return Brightness.set_brightness(quantity);
}
};
/**
* Set the brightness to quantity
* @param {number} quantity The quantity to set
*/
brightness_set(quantity: number): void {
brightness_set = (quantity: number): void => {
return Brightness.set_brightness(quantity);
}
};

/**
* Increase the brightness by quantity
* @param {number} quantity The quantity to increase
* @deprecated Use `brightness_increase`
*/
brightnessIncrease(quantity: number): void {
brightnessIncrease = (quantity: number): void => {
return Brightness.inc_brightness(quantity);
}
};
/**
* Increase the brightness by quantity
* @param {number} quantity The quantity to increase
*/
brightness_increase(quantity: number): void {
brightness_increase = (quantity: number): void => {
return Brightness.inc_brightness(quantity);
}
};

/**
* Decrease the brightness by quantity
* @param {number} quantity The quantity to decrease
* @deprecated Use `brightness_decrease`
*/
brightnessDecrease(quantity: number): void {
brightnessDecrease = (quantity: number): void => {
return Brightness.dec_brightness(quantity);
}
};
/**
* Decrease the brightness by quantity
* @param {number} quantity The quantity to decrease
*/
brightness_decrease(quantity: number): void {
brightness_decrease = (quantity: number): void => {
return Brightness.dec_brightness(quantity);
}
};

/**
* Cancel user authentication that is currently in progress.
*/
cancel_authentication(): boolean {
cancel_authentication = (): boolean => {
return LightDMGreeter.cancelAuthentication();
}
};

/**
* Cancel the automatic login.
*/
cancel_autologin(): boolean {
cancel_autologin = (): boolean => {
return LightDMGreeter.cancelAutologin();
}
};

/**
* Triggers the system to hibernate.
* @returns {boolean} "true" if hibernation initiated, otherwise "false"
*/
hibernate(): boolean {
hibernate = (): boolean => {
return LightDM.hibernate();
}
};

/**
* Provide a response to a prompt.
* @param {string} response
*/
respond(response: string): boolean {
respond = (response: string): boolean => {
return LightDMGreeter.respond(response);
}
};

/**
* Triggers the system to restart.
* @returns {boolean} "true" if restart initiated, otherwise "false"
*/
restart(): boolean {
restart = (): boolean => {
return LightDM.restart();
}
};

/**
* Set the language for the currently authenticated user.
* @param {string} language The language in the form of a locale specification (e.g.
* 'de_DE.UTF-8')
* @returns {boolean} "true" if successful, otherwise "false"
*/
set_language(language: string): boolean {
set_language = (language: string): boolean => {
if (this.is_authenticated) {
return LightDMGreeter.setLanguage(language);
}
return false;
}
};

/**
* Triggers the system to shutdown.
* @returns {boolean} "true" if shutdown initiated, otherwise "false"
*/
shutdown(): boolean {
shutdown = (): boolean => {
return LightDM.shutdown();
}
};

/**
* Start a session for the authenticated user.
* @param {string|null} session The session to log into or "null" to use the default.
* @returns {boolean} "true" if successful, otherwise "false"
*/
start_session(session: string | null): boolean {
start_session = (session: string | null): boolean => {
try {
const started = LightDMGreeter.startSessionSync(session);
if (started || this.is_authenticated) reset_screensaver();
Expand All @@ -535,15 +535,15 @@ export class Greeter {
);
return false;
}
}
};

/**
* Triggers the system to suspend/sleep.
* @returns {boolean} "true" if suspend/sleep initiated, otherwise "false"
*/
suspend(): boolean {
suspend = (): boolean => {
return LightDM.suspend();
}
};
}

function get_layouts(config_layouts: string[]): LightDMLayout[] {
Expand Down Expand Up @@ -665,7 +665,7 @@ export class ThemeUtils {
* @param {Boolean} only_images Include only images in the results. Default `true`.
* @param {function(String[])} callback Callback function to be called with the result.
*/
dirlist(dir_path: string, only_images = true): string[] {
dirlist = (dir_path: string, only_images = true): string[] => {
if (!dir_path || typeof dir_path !== "string" || dir_path === "/") {
return [];
}
Expand Down Expand Up @@ -712,7 +712,7 @@ export class ThemeUtils {
}
//console.log(dir_path, result);
return result;
}
};
}

function reduceArray<T>(arr: unknown[], func: (arg: unknown) => T): T[] {
Expand Down Expand Up @@ -746,8 +746,7 @@ function handler(
let value = undefined;

if (typeof pr === "function") {
const func: (...v: unknown[]) => unknown = pr.bind(accesor);
value = func(...args);
value = pr(...args);
} else {
if (args.length > 0 && ac && ac.set) {
ac.set(args[0]);
Expand Down
6 changes: 3 additions & 3 deletions ts/utils/battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class Battery {

private _init(): void {
if (this._batteries.length == 0) {
scandir_line(this.ps_path, this._update_batteries.bind(this));
scandir_line(this.ps_path, this._update_batteries);
}
this.acpi_listen();
this.full_update();
}

private _update_batteries(line: string): void {
private _update_batteries = (line: string): void => {
const match = line.match(/BAT\w+/);
if (match) {
this._batteries.push({
Expand All @@ -49,7 +49,7 @@ class Battery {
const ac = line.match(/A\w+/);
this._ac = ac ? ac[0] : this._ac;
}
}
};

get name(): string {
return this._batteries[0].name;
Expand Down