From 0622ce72a036c09345ec6631e5bef8bfd514c261 Mon Sep 17 00:00:00 2001 From: Daniel Sheeler Date: Fri, 24 May 2024 15:09:06 -0500 Subject: [PATCH] Updates to pass eslint --- lib/md5.js | 24 ++++++++++----------- src/extension.js | 49 +++++++++++++++++++++---------------------- src/shortcutButton.js | 21 ++++++++++--------- src/utils/logger.js | 8 +++---- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/md5.js b/lib/md5.js index 88c0a70..849131f 100644 --- a/lib/md5.js +++ b/lib/md5.js @@ -7,7 +7,7 @@ * * Licensed under the MIT license: * http://www.opensource.org/licenses/MIT - * + * * Based on * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. @@ -18,7 +18,6 @@ */ /*jslint bitwise: true */ -/*global unescape, define */ 'use strict'; @@ -27,7 +26,7 @@ * to work around bugs in some JS interpreters. */ function safe_add(x, y) { - var lsw = (x & 0xFFFF) + (y & 0xFFFF), + const lsw = (x & 0xFFFF) + (y & 0xFFFF), msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } @@ -66,7 +65,7 @@ x[len >> 5] |= 0x80 << (len % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; - var i, olda, oldb, oldc, oldd, + let i, olda, oldb, oldc, oldd, a = 1732584193, b = -271733879, c = -1732584194, @@ -158,7 +157,7 @@ * Convert an array of little-endian words to a string */ function binl2rstr(input) { - var i, + let i, output = ''; for (i = 0; i < input.length * 32; i += 8) { output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF); @@ -171,7 +170,7 @@ * Characters >255 have their high-byte silently ignored. */ function rstr2binl(input) { - var i, + let i, output = []; output[(input.length >> 2) - 1] = undefined; for (i = 0; i < output.length; i += 1) { @@ -194,12 +193,13 @@ * Calculate the HMAC-MD5, of a key and some data (raw strings) */ function rstr_hmac_md5(key, data) { - var i, + let i, bkey = rstr2binl(key), ipad = [], opad = [], hash; - ipad[15] = opad[15] = undefined; + ipad[15] = undefined; + opad[15] = undefined; if (bkey.length > 16) { bkey = binl_md5(bkey, key.length * 8); } @@ -215,10 +215,10 @@ * Convert a raw string to a hex string */ function rstr2hex(input) { - var hex_tab = '0123456789abcdef', - output = '', - x, - i; + const hex_tab = '0123456789abcdef'; + let x, + i, + output = ''; for (i = 0; i < input.length; i += 1) { x = input.charCodeAt(i); output += hex_tab.charAt((x >>> 4) & 0x0F) + diff --git a/src/extension.js b/src/extension.js index 2a54a06..bc20fa3 100644 --- a/src/extension.js +++ b/src/extension.js @@ -24,7 +24,7 @@ export default class GravatarExtension extends Extension { this.notifSource = null; this.previousKeybinding = ""; } - + /* *********************************************** * Public Methods * @@ -44,7 +44,7 @@ export default class GravatarExtension extends Extension { this.addKeybinding(); }); } - + disable() { this.logger.debug('Disabling'); this.user = null; @@ -53,30 +53,30 @@ export default class GravatarExtension extends Extension { this.settings.disconnect(this.emailChangedId); this.emailChangedId = null; } - + if (this.keybindingChangedId) { this.settings.disconnect(this.keybindingChangedId); this.keybindingChangedId = null; } - + if (this.userLoop) { clearInterval(this.userLoop); this.userLoop = null; } - + if (this.httpSession) { this.httpSession.abort(); this.httpSession = null; } this.logger = null; } - + /* *********************************************** * Private Methods * *********************************************** */ - + addKeybinding() { this.logger.debug("Adding keybinding"); this.previousKeybinding = this.settings.get_strv("gravatar-ondemand-keybinding")[0]; @@ -94,14 +94,14 @@ export default class GravatarExtension extends Extension { } ) } - + removeKeybinding() { this.logger.debug(`Remove keybinding ${this.previousKeybinding}`); if (this.previousKeybinding) { Main.wm.removeKeybinding('gravatar-ondemand-keybinding'); } } - + waitForUser(cb) { // This fixes an issue where sometimes this.user is not // initialized when the extension loads @@ -127,23 +127,23 @@ export default class GravatarExtension extends Extension { return null; }, 1000); } - + /* Settings */ getIconSize() { return this.settings.get_int('icon-size'); } - + getHash() { const email = this.settings.get_string('email').toLowerCase(); this.logger.debug(`Hashing "${email}"`); return md5(email); } - + /* Set Icon */ setIcon(icon) { this.user.set_icon_file(icon); } - + /* Download From Gravatar */ loadIcon() { const email = this.settings.get_string('email').toLowerCase(); @@ -155,7 +155,7 @@ export default class GravatarExtension extends Extension { const url = `http://www.gravatar.com/avatar/${hash}?s=${this.getIconSize()}&d=404`; const request = Soup.Message.new('GET', url); const icon = Gio.file_new_for_path(`${this.tmpDir}/${Date.now()}_${hash}`); - + // initialize session if (!this.httpSession) { this.logger.debug('Creating new http session'); @@ -166,12 +166,12 @@ export default class GravatarExtension extends Extension { this.logger.debug(`Saving to ${icon.get_path()}`); const fstream = icon.replace(null, false, Gio.FileCreateFlags.NONE, null); this.httpSession.send_and_splice_async( - request, - fstream, + request, + fstream, Gio.OutputStreamSpliceFlags.CLOSE_TARGET, 0, null, - (session, result, data) => { + (session, result) => { if (session.send_and_splice_finish(result) > -1) { if (session.get_async_result_message(result).get_status() !== Soup.Status.NOT_FOUND) { this.setIcon(icon.get_path()); @@ -190,29 +190,29 @@ export default class GravatarExtension extends Extension { this.logger.error(e.message); } } - + showNotification(title, message, gicon) { if (!this.settings.get_boolean('notifications')) return; - if (this.notifSource == null) { + if (this.notifSource === null) { // We have to prepare this only once this.notifSource = new MessageTray.Source({ title: this.metadata.name.toString(), icon: Gio.icon_new_for_string(GLib.build_filenamev([this.path, 'ui', 'icons', 'hicolor', 'scalable', 'actions', 'gravatar.svg'])), }); - + // Take care of not leaving unneeded sources this.notifSource.connect('destroy', ()=>{this.notifSource = null;}); Main.messageTray.add(this.notifSource); } - + let notification = null; // We do not want to have multiple notifications stacked // instead we will update previous - if (this.notifSource.notifications.length == 0) { + if (this.notifSource.notifications.length === 0) { notification = new MessageTray.Notification({ - source: this.notifSource, - title: title, + source: this.notifSource, + title: title, body: message, gicon: gicon }); @@ -227,4 +227,3 @@ export default class GravatarExtension extends Extension { this.notifSource.addNotification(notification); } } - \ No newline at end of file diff --git a/src/shortcutButton.js b/src/shortcutButton.js index 3b5587b..c63e718 100644 --- a/src/shortcutButton.js +++ b/src/shortcutButton.js @@ -29,11 +29,11 @@ export class OnDemandShortcutButton extends Gtk.Stack { this.settings = settings; this.dialog = null; this.valign = Gtk.Align.CENTER; - + this.chooseButton = new Gtk.Button({ label: "Choose...", }); - + this.editBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, }); @@ -42,7 +42,7 @@ export class OnDemandShortcutButton extends Gtk.Stack { this.changeButton = new Gtk.Button({ tooltip_text: "Change keyboard shortcut", }) - + this.clearButton = new Gtk.Button({ label: "Clear", }) @@ -54,7 +54,7 @@ export class OnDemandShortcutButton extends Gtk.Stack { this.shortcutLabel = new Gtk.ShortcutLabel({ accelerator: this.keybinding, }); - + //this.settings.connect("changed::gravatar-ondemand-keybinding", this.shortcutLabel, "accelerator", Gio.SettingsBindFlags.DEFAULT); this.bind_property("keybinding", this.shortcutLabel, "accelerator", Gio.SettingsBindFlags.DEFAULT); this.changeButton.set_child(this.shortcutLabel); @@ -74,14 +74,14 @@ export class OnDemandShortcutButton extends Gtk.Stack { } activate() { - if (this.keybinding) + if (this.keybinding) return this.editBox.get_first_child().activate(); - else + else return this.chooseButton.activate(); } openDialog() { - if (this.dialog == null) { + if (this.dialog === null) { this.statusPage = new Adw.StatusPage({ title: "Press your keyboard shortcut...", icon_name: "preferences-desktop-keyboard-shortcuts-symbolic", @@ -102,7 +102,7 @@ export class OnDemandShortcutButton extends Gtk.Stack { hexpand: true, child: this.overlay, }) - + this.dialog = new Adw.Window({ modal: true, default_width: 440, @@ -114,13 +114,13 @@ export class OnDemandShortcutButton extends Gtk.Stack { }); this.eventControllerKey.connect("key-pressed", this.onKeyPressed.bind(this)) this.dialog.add_controller(this.eventControllerKey); - + } this.dialog.transient_for = this.get_root(); this.dialog.present(); } - onKeybindingChanged(button) { + onKeybindingChanged() { this.visible_child = this.keybinding ? this.editBox : this.chooseButton; } @@ -195,6 +195,7 @@ function isKeyvalForbidden(keyval) { * representing the key combo. * @returns {boolean} `true` if the key combo is a valid binding. */ +// eslint-disable-next-line complexity function isBindingValid({ mask, keycode, keyval }) { if ((mask === 0 || mask === Gdk.SHIFT_MASK) && keycode !== 0) { if ( diff --git a/src/utils/logger.js b/src/utils/logger.js index 44eae67..04efb22 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -13,8 +13,8 @@ export const GravatarLogger = new GObject.registerClass({ ), } }, class GravatarLogger extends GObject.Object { - _init(settings) { - super._init(); + constructor(settings) { + super(); this.settings = settings; this.settings.bind('debug', this, 'debugging_on', Gio.SettingsBindFlags.DEFAULT); @@ -33,8 +33,8 @@ export const GravatarLogger = new GObject.registerClass({ console.log(`[DEBUG ]${this.prepareMessage(msg)}`); } } - + prepareMessage(msg) { return `[Gravatar] ${msg}`; } -}); \ No newline at end of file +});