Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Refactor codebase to comply with JSHint
Browse files Browse the repository at this point in the history
This covers mostly missing or wrong ``;`` usage.

Ref.: projecthamster#229
  • Loading branch information
elbenfreund committed Mar 16, 2018
1 parent 624bf07 commit 84646cc
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 63 deletions.
19 changes: 11 additions & 8 deletions extension/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ function Controller(extensionMeta) {
this.shouldEnable = false;
Main.wm.removeKeybinding("show-hamster-dropdown");

global.log('Shutting down hamster-shell-extension.')
this._removeWidget(this.placement)
global.log('Shutting down hamster-shell-extension.');
this._removeWidget(this.placement);
Main.panel.menuManager.removeMenu(this.panelWidget.menu);
GLib.source_remove(this.panelWidget.timeout);
this.panelWidget.actor.destroy();
this.panelWidget.destroy();
this.panelWidget = null;
this.apiProxy = null;
Expand Down Expand Up @@ -216,7 +219,7 @@ function Controller(extensionMeta) {
// So unless can provide some insight here, this hack does the job.
let foo = function([activities]){return activities;};
return foo(activities);
};
}

let result = getActivities(this);
this.activities = result;
Expand All @@ -236,7 +239,7 @@ function Controller(extensionMeta) {
Main.panel._addToPanelBox('dateMenu', dateMenu, -1, Main.panel._rightBox);
} else if (placement == 2) {
// 'Replace activities'
let activitiesMenu = Main.panel._leftBox.get_children()[0].get_children()[0].get_children()[0].get_children()[0]
let activitiesMenu = Main.panel._leftBox.get_children()[0].get_children()[0].get_children()[0].get_children()[0];
// If our widget replaces the 'Activities' menu in the panel,
// this property stores the original text so we can restore it
// on ``this.disable``.
Expand All @@ -246,7 +249,7 @@ function Controller(extensionMeta) {
} else {
// 'Default'
Main.panel.addToStatusArea("hamster", this.panelWidget, 0, "right");
};
}
},

_removeWidget: function(placement) {
Expand All @@ -262,15 +265,15 @@ function Controller(extensionMeta) {
Main.panel._centerBox.remove_actor(this.panelWidget.container);
} else if (placement == 2) {
// We replaced the 'Activities' menu
let activitiesMenu = Main.panel._leftBox.get_children()[0].get_children()[0].get_children()[0].get_children()[0]
let activitiesMenu = Main.panel._leftBox.get_children()[0].get_children()[0].get_children()[0].get_children()[0];
activitiesMenu.set_text(this._activitiesText);
Main.panel._leftBox.remove_actor(this.panelWidget.container);
} else {
Main.panel._rightBox.remove_actor(this.panelWidget.container);
};
}
},
};
};
}


function init(extensionMeta) {
Expand Down
4 changes: 2 additions & 2 deletions extension/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ const HamsterSettingsWidget = new GObject.Class({
vbox.add(new Gtk.Label({label: "Reload gnome shell after updating prefs (alt+f2 > r)",
margin_top: 70}));

let version_text = ExtensionUtils.getCurrentExtension().metadata.version
let version_label_text = "You are running hamster-shell-extension version " + version_text
let version_text = ExtensionUtils.getCurrentExtension().metadata.version;
let version_label_text = "You are running hamster-shell-extension version " + version_text;
vbox.add(new Gtk.Label({label: version_label_text, margin_top: 10}));
},

Expand Down
6 changes: 3 additions & 3 deletions extension/stuff.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function formatDurationHuman(total_seconds) {
// We only care for "full minutes".
let minutes = remaining_seconds / 60;

let result = ''
let result = '';

if (hours > 0 || minutes > 0) {
if (hours > 0) {
Expand Down Expand Up @@ -106,7 +106,7 @@ function fromDbusFact(fact) {
id: fact[0]
};
return result;
};
}

function fromDbusFacts(facts) {
let res = [];
Expand All @@ -115,4 +115,4 @@ function fromDbusFacts(facts) {
}

return res;
};
}
8 changes: 4 additions & 4 deletions extension/widgets/categoryTotalsWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ var CategoryTotalsWidget = new Lang.Class({
byCategory[fact.category] = (byCategory[fact.category] || 0) + fact.delta;
if (categories.indexOf(fact.category) == -1)
categories.push(fact.category);
};
}

let string = "";
for (let category of categories) {
string += category + ": " + Stuff.formatDurationHours(byCategory[category]) + ", ";
};
}
// strip trailing comma
return string.slice(0, string.length - 2);
};
}

this.set_text(getString(facts))
this.set_text(getString(facts));
},
});
12 changes: 6 additions & 6 deletions extension/widgets/factsBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ Copyright (c) 2016 - 2018 Eric Goller / projecthamster <elbenfreund@projecthamst

const Lang = imports.lang;
const St = imports.gi.St;
const PopupMenu = imports.ui.popupMenu
const PopupMenu = imports.ui.popupMenu;
const Clutter = imports.gi.Clutter;
const Mainloop = imports.mainloop;
const GLib = imports.gi.GLib;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const Stuff = Me.imports.stuff;
const OngoingFactEntry = Me.imports.widgets.ongoingFactEntry.OngoingFactEntry
const CategoryTotalsWidget = Me.imports.widgets.categoryTotalsWidget.CategoryTotalsWidget
const TodaysFactsWidget = Me.imports.widgets.todaysFactsWidget.TodaysFactsWidget
const OngoingFactEntry = Me.imports.widgets.ongoingFactEntry.OngoingFactEntry;
const CategoryTotalsWidget = Me.imports.widgets.categoryTotalsWidget.CategoryTotalsWidget;
const TodaysFactsWidget = Me.imports.widgets.todaysFactsWidget.TodaysFactsWidget;


/**
Expand All @@ -46,7 +46,7 @@ var FactsBox = new Lang.Class({
_init: function(controller, panelWidget) {
this.parent({reactive: false});

this._controller = controller
this._controller = controller;

// Setup main layout box
let main_box = new St.BoxLayout({style_class: 'hamster-box'});
Expand Down Expand Up @@ -74,7 +74,7 @@ var FactsBox = new Lang.Class({
main_box.add(this.todaysFactsWidget);

// Setup category summery
this.summaryLabel = new CategoryTotalsWidget()
this.summaryLabel = new CategoryTotalsWidget();
main_box.add(this.summaryLabel);
},

Expand Down
18 changes: 9 additions & 9 deletions extension/widgets/ongoingFactEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ var OngoingFactEntry = new Lang.Class({
hint_text: _("Enter activity...")
});

this._controller = controller
this._prevText = ''
this._controller = controller;
this._prevText = '';
// Seems to be populate by GetActivities.
this._autocompleteActivities = [];
this._runningActivitiesQuery = null;
Expand Down Expand Up @@ -92,11 +92,11 @@ var OngoingFactEntry = new Lang.Class({
let result = ignoreKeys.indexOf(key);
if (result == -1) {
result = false;
} else{
} else {
result = true;
};
}
return result;
};
}

let symbol = evt.get_key_symbol();
// [FIXME]
Expand All @@ -121,7 +121,7 @@ var OngoingFactEntry = new Lang.Class({
(match = text.match(/^-\d+ /))) {
starttime = text.substring(0, match[0].length);
activitytext = text.substring(match[0].length);
};
}

// [FIXME]
// Should be a separate local function.
Expand All @@ -135,7 +135,7 @@ var OngoingFactEntry = new Lang.Class({
}
this._prevText = text;

if (checkIfIgnoredKey(symbol)) { return };
if (checkIfIgnoredKey(symbol)) { return; }

// [FIXME]
// Investigate if we can move this into a dedicated 'autocomplete' function.
Expand Down Expand Up @@ -179,7 +179,7 @@ var OngoingFactEntry = new Lang.Class({
this.get_clutter_text().set_selection(text.length, completion.length);

this._prevText = completion.toLowerCase();
};
};
}
}
},
});
24 changes: 12 additions & 12 deletions extension/widgets/panelWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Gio = imports.gi.Gio;
const Clutter = imports.gi.Clutter;
const PanelMenu = imports.ui.panelMenu;
const St = imports.gi.St;
const PopupMenu = imports.ui.popupMenu
const PopupMenu = imports.ui.popupMenu;
const GLib = imports.gi.GLib;

const Me = imports.misc.extensionUtils.getCurrentExtension();
Expand Down Expand Up @@ -61,7 +61,7 @@ var PanelWidget = new Lang.Class({
// What is the parameter?
this.parent(0.0);

this._controller = controller
this._controller = controller;
// [FIXME]
// Still needed?
this._extensionMeta = controller.extensionMeta;
Expand Down Expand Up @@ -167,10 +167,10 @@ var PanelWidget = new Lang.Class({
let result = null;
if (facts.length) {
let lastFact = facts[facts.length - 1];
if (!lastFact.endTime) { result = lastFact };
};
if (!lastFact.endTime) { result = lastFact; }
}
return result;
};
}

let facts = [];

Expand All @@ -180,13 +180,13 @@ var PanelWidget = new Lang.Class({
log(err);
} else if (response.length > 0) {
facts = Stuff.fromDbusFacts(response);
};
}

let ongoingFact = getOngoingFact(facts);

this.updatePanelDisplay(ongoingFact);
this.factsBox.refresh(facts, ongoingFact);
};
}

// [FIXME]
// This should really be a synchronous call fetching the facts.
Expand Down Expand Up @@ -228,17 +228,17 @@ var PanelWidget = new Lang.Class({
let result = _("No activity");
if (fact) {
result = "%s %s".format(fact.name, Stuff.formatDuration(fact.delta));
};
}
return result;
};
}
/**
* Returns the appropriate icon image depending on ``fact``.
*/
function getIcon(panelWidget) {
let result = panelWidget._idleIcon;
if (fact) { result = panelWidget._trackingIcon };
if (fact) { result = panelWidget._trackingIcon; }
return result;
};
}

// 0 = show label, 1 = show just icon, 2 = show label and icon
switch (this._settings.get_int("panel-appearance")) {
Expand All @@ -258,7 +258,7 @@ var PanelWidget = new Lang.Class({
this.panelLabel.set_text(getLabelString(fact));
this.panelLabel.show();
break;
};
}
},

/**
Expand Down
36 changes: 17 additions & 19 deletions extension/widgets/todaysFactsWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ var TodaysFactsWidget = new Lang.Class({
// as a single issue.
otherFact.tags.join(",") != fact.tags.join(",")) {
result = false;
};
}
return result;
};
}

/**
* Callback for the 'openEditDialog'-Button.
Expand All @@ -94,7 +94,7 @@ var TodaysFactsWidget = new Lang.Class({
function onOpenEditDialog(button, event) {
controller.windowsProxy.editSync(GLib.Variant.new('i', [fact.id]));
menu.close();
};
}

/**
* Callback for the 'onContinue'-Button.
Expand All @@ -107,10 +107,8 @@ var TodaysFactsWidget = new Lang.Class({
function onContinueButton(button, event) {
// [FIXME]
// This probably should be a "serialize" method of the fact object.
let fact = button.fact
let factStr = fact.name
+ "@" + fact.category
+ ", " + (fact.description);
let fact = button.fact;
let factStr = fact.name + "@" + fact.category + ", " + (fact.description);
if (fact.tags.length) {
factStr += " #" + fact.tags.join(", #");
}
Expand All @@ -119,18 +117,18 @@ var TodaysFactsWidget = new Lang.Class({
// not interested in the new id - this shuts up the warning
}));
menu.close();
};
}

// Construct the ``Label`` rendering the start- and endtime information.
let timeLabel = new St.Label({style_class: 'cell-label'});
let timeString;
let start_string = "%02d:%02d - ".format(fact.startTime.getHours(), fact.startTime.getMinutes());
if (fact.endTime) {
let end_string = "%02d:%02d".format(fact.endTime.getHours(), fact.endTime.getMinutes());
timeString = start_string + end_string
timeString = start_string + end_string;
} else {
timeString = start_string
};
timeString = start_string;
}
timeLabel.set_text(timeString);

// Construct the ``Label``rendering the remaining fact info.
Expand All @@ -154,42 +152,42 @@ var TodaysFactsWidget = new Lang.Class({
// Construct a 'start previous fact's activity as new' button.
// This is only done if the *ongoing fact* activity is actually
// different from the one we currently process.
let continueButton = null
let continueButton = null;
if (!checkSameActivity(fact, ongoingFact)) {

let continueIcon = new St.Icon({icon_name: "media-playback-start-symbolic", icon_size: 16});
continueButton = new St.Button({style_class: 'clickable cell-button'});
continueButton.set_child(continueIcon);
continueButton.fact = fact;
continueButton.connect('clicked', Lang.bind(this, onContinueButton));
};
}

//The order of the array will be the order in which they will be added to the row.
let result = [timeLabel, factLabel, deltaLabel, editButton];

if (continueButton) {
result.push(continueButton);
};
return result
}
return result;

};
}

let rowCount = 0;
let layout = this.facts_widget.layout_manager;
for (let fact of facts) {
let rowComponents = constructRow(fact, ongoingFact, this._controller, this._panelWidget.menu);
for (let component of rowComponents) {
layout.pack(component, rowComponents.indexOf(component), rowCount);
};
}
rowCount += 1;
};
}
},

/**
* Clear the widget and populate it anew.
*/
refresh: function(facts, ongoingFact) {
this.facts_widget.remove_all_children();
this.populateFactsWidget(facts, ongoingFact)
this.populateFactsWidget(facts, ongoingFact);
},
});

0 comments on commit 84646cc

Please sign in to comment.