Skip to content

Commit

Permalink
some reorganizing. hope this doesn't cause i18n issues
Browse files Browse the repository at this point in the history
  • Loading branch information
toppk committed Oct 6, 2023
1 parent 9959281 commit 9117377
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 370 deletions.
14 changes: 11 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

env:
es2021: true
extends: 'eslint:recommended'
extends: "eslint:recommended"
rules:
# See: https://eslint.org/docs/latest/rules/#possible-problems
array-callback-return: error
Expand All @@ -29,7 +29,9 @@ rules:
complexity: warn
consistent-return: error
default-param-last: error
eqeqeq: error
eqeqeq:
- error
- smart
no-array-constructor: error
no-caller: error
no-extend-native: error
Expand Down Expand Up @@ -83,8 +85,14 @@ rules:
MethodDefinition[key.name="_init"]
CallExpression[arguments.length<=1][callee.object.type="Super"][callee.property.name="_init"]
message: Use constructor() and super()
# GJS Globals
# GJS Globals
# camelcase:
# - error
# - properties: never
# allow: [^vfunc_, ^on_]
prefer-arrow-callback: error
globals:
global: readonly
ARGV: readonly
Debugger: readonly
GIRepositoryGType: readonly
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
PKG_NAME = gnome-shell-extension-openweather
UUID = [email protected]
BASE_MODULES = metadata.json COPYING AUTHORS
SRC_MODULES = extension.js openweathermap.js prefs.js stylesheet.css
PREFS_MODULES = generalPage.js layoutPage.js locationsPage.js aboutPage.js
SRC_MODULES = extension.js openweathermap.js prefs.js stylesheet.css constants.js
PREFS_MODULES = generalPage.js layoutPage.js locationsPage.js aboutPage.js searchResultsWindow.js
EXTRA_DIRECTORIES = media
TOLOCALIZE = $(addprefix src/, extension.js openweathermap.js prefs.js) \
TOLOCALIZE = $(addprefix src/, extension.js openweathermap.js prefs.js constants.js) \
$(addprefix src/preferences/, $(PREFS_MODULES)) \
schemas/org.gnome.shell.extensions.openweather.gschema.xml
MSGSRC = $(wildcard po/*.po)
Expand Down
59 changes: 59 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const WeatherProvider = {
OPENWEATHERMAP: 0,
};

const WeatherUnits = {
CELSIUS: 0,
FAHRENHEIT: 1,
KELVIN: 2,
RANKINE: 3,
REAUMUR: 4,
ROEMER: 5,
DELISLE: 6,
NEWTON: 7,
};

const WeatherWindSpeedUnits = {
KPH: 0,
MPH: 1,
MPS: 2,
KNOTS: 3,
FPS: 4,
BEAUFORT: 5,
};

const WeatherPressureUnits = {
HPA: 0,
INHG: 1,
BAR: 2,
PA: 3,
KPA: 4,
ATM: 5,
AT: 6,
TORR: 7,
PSI: 8,
MMHG: 9,
MBAR: 10,
};

const WeatherPosition = {
CENTER: 0,
RIGHT: 1,
LEFT: 2,
};

// Keep enums in sync with GSettings schemas
const GeolocationProvider = {
OPENSTREETMAPS: 0,
GEOCODE: 1,
MAPQUEST: 2,
};

export {
WeatherProvider,
WeatherUnits,
WeatherWindSpeedUnits,
WeatherPressureUnits,
WeatherPosition,
GeolocationProvider,
};
79 changes: 8 additions & 71 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,17 @@ import * as PopupMenu from "resource:///org/gnome/shell/ui/popupMenu.js";
import * as GnomeSession from "resource:///org/gnome/shell/misc/gnomeSession.js";

import * as OpenWeatherMap from "./openweathermap.js";
import {
WeatherUnits,
WeatherWindSpeedUnits,
WeatherPressureUnits,
WeatherPosition,
} from "./constants.js";

let _firstBoot = 1;
let _timeCacheCurrentWeather;
let _timeCacheForecastWeather;
// Keep enums in sync with GSettings schemas
const WeatherProvider = {
OPENWEATHERMAP: 0,
};
const WeatherUnits = {
CELSIUS: 0,
FAHRENHEIT: 1,
KELVIN: 2,
RANKINE: 3,
REAUMUR: 4,
ROEMER: 5,
DELISLE: 6,
NEWTON: 7,
};
const WeatherWindSpeedUnits = {
KPH: 0,
MPH: 1,
MPS: 2,
KNOTS: 3,
FPS: 4,
BEAUFORT: 5,
};
const WeatherPressureUnits = {
HPA: 0,
INHG: 1,
BAR: 2,
PA: 3,
KPA: 4,
ATM: 5,
AT: 6,
TORR: 7,
PSI: 8,
MMHG: 9,
MBAR: 10,
};
const WeatherPosition = {
CENTER: 0,
RIGHT: 1,
LEFT: 2,
};

//hack (for Wayland?) via https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1997
//https://github.com/home-sweet-gnome/dash-to-panel/commit/31e7275608fb0a4a13e406b1f841b084404c1f9e
Expand Down Expand Up @@ -1608,47 +1575,17 @@ class OpenWeatherMenuButton extends PanelMenu.Button {
}

export default class OpenWeatherExtension extends Extension {
/**
* This class is constructed once when your extension is loaded, not
* enabled. This is a good time to setup translations or anything else you
* only do once.
*
* You MUST NOT make any changes to GNOME Shell, connect any signals or add
* any event sources here.
*
* @param {ExtensionMeta} metadata - An extension meta object
*/
constructor(metadata) {
super(metadata);
console.debug(`constructing ${this.metadata.name}`);
}

/**
* This function is called when your extension is enabled, which could be
* done in GNOME Extensions, when you log in or when the screen is unlocked.
*
* This is when you should setup any UI for your extension, change existing
* widgets, connect signals or modify GNOME Shell's behavior.
*/
enable() {
console.debug(`enabling ${this.metadata.name}`);
console.log(`enabling ${this.metadata.name}`);
this.openWeatherMenu = new OpenWeatherMenuButton(
this.metadata,
this.getSettings()
);
Main.panel.addToStatusArea("openWeatherMenu", this.openWeatherMenu);
}

/**
* This function is called when your extension is uninstalled, disabled in
* GNOME Extensions or when the screen locks.
*
* Anything you created, modified or setup in enable() MUST be undone here.
* Not doing so is the most common reason extensions are rejected in review!
*/
disable() {
console.debug(`disabling ${this.metadata.name}`);

console.log(`disabling ${this.metadata.name}`);
this.openWeatherMenu.stop();
this.openWeatherMenu.destroy();
this.openWeatherMenu = null;
Expand Down
Loading

0 comments on commit 9117377

Please sign in to comment.