Skip to content

Commit

Permalink
Merge pull request #40 from noroadsleft000/release/version-13
Browse files Browse the repository at this point in the history
Release/version 13
  • Loading branch information
noroadsleft000 authored Mar 22, 2022
2 parents 9287c70 + affb829 commit d7cdbcc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
7 changes: 7 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const { DeviceMonitor } = Me.imports.net.DeviceMonitor;
const { Logger } = Me.imports.utils.Logger;

class AppClass {
static instance() {
return this._instance || (this._instance = new this());
}

static deleteInstance() {
this._instance = undefined;
}

constructor() {
const logger = new Logger();
Expand Down
18 changes: 6 additions & 12 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@ const Me = ExtensionUtils.getCurrentExtension();
const { Logger } = Me.imports.utils.Logger;
const { App } = Me.imports.App;
const { initBrodcasters, deinitBrodcasters } = Me.imports.utils.Broadcasters;
const Prefs = Me.imports.prefs;

let logger = undefined;
let app = undefined;
function init() {
logger = new Logger;
logger.info(`initializing 1 ${Me.metadata.name}`);
Logger.info(`initializing ${Me.metadata.name}`);
}

function enable() {
logger.info(`enabling ${Me.metadata.name}`);
Logger.info(`enabling ${Me.metadata.name}`);
initBrodcasters();
app = new App();
app.start();
App.instance().start();
}

function disable() {
logger.info(`disabling ${Me.metadata.name}`);
app.stop();
Logger.info(`disabling ${Me.metadata.name}`);
App.instance().stop();
deinitBrodcasters();
app = undefined;
logger = undefined;
App.deleteInstance();
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"41"
],
"url" : "https://github.com/noroadsleft000/gnome-network-stats",
"version": 12
"version": 13
}
13 changes: 5 additions & 8 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const SettingRowOrder = Object.freeze({

class PrefsApp {
constructor() {
this._logger = new Logger;
this._rows = {};
this.main = new Gtk.Grid({
margin_top: 10,
Expand Down Expand Up @@ -126,7 +125,7 @@ class PrefsApp {
_hideRow(row) {
const label = this.main.get_child_at(0, row);
const input = this.main.get_child_at(1, row);
//this._logger.log(`${row}. label: ${label} input: ${input}`);
//Logger.log(`${row}. label: ${label} input: ${input}`);
if (label) {
this.main.remove(label);
}
Expand All @@ -137,7 +136,7 @@ class PrefsApp {

_showRow(row) {
const { label, input } = this._rows[row];
//this._logger.log(`${row}. label: ${label} input: ${input}`);
//Logger.log(`${row}. label: ${label} input: ${input}`);
if (!label.parent && !input.parent) {
this.main.attach(label, 0, row, 1, 1);
this.main.attach(input, 1, row, 1, 1);
Expand Down Expand Up @@ -379,7 +378,7 @@ class PrefsApp {

updateControls() {
const resetSchedule = this.schema.get_string(SettingKeys.RESET_SCHEDULE);
//this._logger.log(`resetSchedule: ${resetSchedule}`);
//Logger.log(`resetSchedule: ${resetSchedule}`);
switch(resetSchedule) {
default:
case ResetSchedule.DAILY:
Expand Down Expand Up @@ -420,8 +419,7 @@ class PrefsApp {

/** Initialize language/locale */
function init() {
const logger = new Logger;
logger.debug("init");
Logger.debug("init");
const localeDir = Me.dir.get_child("locale");
if (localeDir.query_exists(null)) {
Gettext.bindtextdomain("network-stats", localeDir.get_path());
Expand All @@ -430,8 +428,7 @@ function init() {

/** Build settings view */
function buildPrefsWidget() {
const logger = new Logger;
logger.debug("buildPrefsWidget");
Logger.debug("buildPrefsWidget");
const widget = new PrefsApp();
if (isGtk3()) {
widget.main.show_all();
Expand Down
24 changes: 22 additions & 2 deletions utils/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@ const Me = ExtensionUtils.getCurrentExtension();
*/

class LoggerClass {
constructor() {
this.test = "Hello";
static instance() {
return this._instance || (this._instance = new this());
}

static log(...args) {
this.instance()._printLog("LOG", args);
}

static debug(...args) {
this.instance()._printLog("DEBUG", args);
}

static info(...args) {
this.instance()._printLog("INFO", args);
}

static error(...args) {
this.instance()._printLog("ERROR", args);
}

static critical(...args) {
this.instance()._printLog("**CRITICAL", args);
}

_callerInfo(level=3) {
Expand Down

0 comments on commit d7cdbcc

Please sign in to comment.