Skip to content

Commit

Permalink
Updates to pass eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
dsheeler committed May 24, 2024
1 parent a35fccd commit 0622ce7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
24 changes: 12 additions & 12 deletions lib/md5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,7 +18,6 @@
*/

/*jslint bitwise: true */
/*global unescape, define */

'use strict';

Expand All @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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) +
Expand Down
49 changes: 24 additions & 25 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class GravatarExtension extends Extension {
this.notifSource = null;
this.previousKeybinding = "";
}

/*
***********************************************
* Public Methods *
Expand All @@ -44,7 +44,7 @@ export default class GravatarExtension extends Extension {
this.addKeybinding();
});
}

disable() {
this.logger.debug('Disabling');
this.user = null;
Expand All @@ -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];
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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');
Expand All @@ -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());
Expand All @@ -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
});
Expand All @@ -227,4 +227,3 @@ export default class GravatarExtension extends Extension {
this.notifSource.addNotification(notification);
}
}

21 changes: 11 additions & 10 deletions src/shortcutButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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",
})
Expand All @@ -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);
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 (
Expand Down
8 changes: 4 additions & 4 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -33,8 +33,8 @@ export const GravatarLogger = new GObject.registerClass({
console.log(`[DEBUG ]${this.prepareMessage(msg)}`);
}
}

prepareMessage(msg) {
return `[Gravatar] ${msg}`;
}
});
});

0 comments on commit 0622ce7

Please sign in to comment.