Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sakithb committed Nov 19, 2023
1 parent 4867888 commit 3cc16f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
11 changes: 10 additions & 1 deletion debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ lint() {
npx eslint -c .eslintrc.yml *.js
}

lint_fix() {
npx eslint -c .eslintrc.yml *.js --fix
}

PARAMS=();

for i in $@
Expand All @@ -61,7 +65,8 @@ if [[ " ${PARAMS[*]} " =~ " -h" ]]; then
echo " -u Update extension source files";
echo " -d Debug extension";
echo " -t Update translation po files";
echo " -l Lint codebase";
echo " -l Lint codebase (check)";
echo " -f Lint codebase (fix)";
exit;
fi

Expand All @@ -83,4 +88,8 @@ fi

if [[ " ${PARAMS[*]} " =~ " -l " ]]; then
lint;
fi

if [[ " ${PARAMS[*]} " =~ " -f " ]]; then
lint_fix;
fi
10 changes: 5 additions & 5 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Extension, gettext as _ } from "resource:///org/gnome/shell/extensions/extension.js";
import { MediaControls } from "./widget.js";

let mc_extension;
let mcExtension;

export default class MediaControlsExtension extends Extension {
enable() {
log(_("[MediaControls] Enabling"));
mc_extension = new MediaControls();
mc_extension.enable(this);
mcExtension = new MediaControls();
mcExtension.enable(this);
}

disable() {
log(_("[MediaControls] Disabling"));
mc_extension.disable();
mc_extension = null;
mcExtension.disable();
mcExtension = null;
}
}
31 changes: 15 additions & 16 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import GLib from "gi://GLib";
import Gio from "gi://Gio";
import Soup from "gi://Soup";
import Pango from "gi://Pango";

Expand All @@ -19,45 +18,45 @@ export const msToHHMMSS = (ms) => {
seconds = seconds - hours * 3600 - minutes * 60;

if (hours < 10) {
hours = "0" + hours;
hours = `0${hours}`;
}

if (minutes < 10) {
minutes = "0" + minutes;
minutes = `0${minutes}`;
}

if (seconds < 10) {
seconds = "0" + seconds;
seconds = `0${seconds}`;
}

if (hours === "00") {
return minutes + ":" + seconds;
return `${minutes}:${seconds}`;
}

if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
return "--";
}

return hours + ":" + minutes + ":" + seconds;
return `${hours}:${minutes}:${seconds}`;
};

export const parseMetadata = (_metadata) => {
if (!_metadata) {
return _metadata;
}

let metadata = {};
for (let key in metadataKeys) {
let val = _metadata[key];
const metadata = {};
for (const key in metadataKeys) {
const val = _metadata[key];
metadata[metadataKeys[key]] = val instanceof GLib.Variant ? val.recursiveUnpack() : val;
}

metadata.isInactive = metadata.title == "" && metadata.artist == "" && metadata.length == 0;
metadata.isInactive = metadata.title === "" && metadata.artist === "" && metadata.length === 0;

let title = metadata.title || metadata.url || metadata.id;

if (title && title === metadata.url) {
let urlParts = metadata.url.split("/");
const urlParts = metadata.url.split("/");
if (urlParts[0] === "file:") {
title = urlParts[urlParts.length - 1];
}
Expand Down Expand Up @@ -87,11 +86,11 @@ export const stripInstanceNumbers = (busName) => {

export const getRequest = (url) => {
return new Promise((resolve, reject) => {
let _session = new Soup.Session();
let _request = Soup.Message.new("GET", url);
_session.send_and_read_async(_request, GLib.PRIORITY_DEFAULT, null, (_session, result) => {
if (_request.get_status() === Soup.Status.OK) {
let bytes = _session.send_and_read_finish(result);
const session = new Soup.Session();
const request = Soup.Message.new("GET", url);
session.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (_session, result) => {
if (request.get_status() === Soup.Status.OK) {
const bytes = _session.send_and_read_finish(result);
resolve(bytes);
} else {
reject(new Error("Soup request not resolved"));
Expand Down

0 comments on commit 3cc16f7

Please sign in to comment.