Skip to content

Commit

Permalink
Merge pull request #33 from CleoMenezesJr/gnome-47
Browse files Browse the repository at this point in the history
release: v47.0
  • Loading branch information
CleoMenezesJr authored Sep 5, 2024
2 parents 64a3f99 + e7a188e commit c7b9170
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ INSTALLNAME = [email protected]
default: build

.PHONY: build
build:
glib-compile-schemas ./[email protected]/schemas

.PHONY: install
install: build
Expand Down
85 changes: 58 additions & 27 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,82 @@ import GObject from "gi://GObject";
import St from "gi://St";
import * as Weather from "resource:///org/gnome/shell/misc/weather.js";
import * as Main from "resource:///org/gnome/shell/ui/main.js";
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';

let panelWeather = null;
let topBox, statusArea, dateMenu, weather, network, networkIcon;
let statusArea, dateMenu, weather, network, networkIcon, isWeatherAfterClock;

export default class weatherOClock extends Extension {
constructor(metadata) {
super(metadata);

this._topBox = null;
this._positionChangeListener = null;
this._settings = null;
}

export default class weatherOClock {
enable() {
if (!panelWeather) {
statusArea = Main.panel.statusArea;
dateMenu = statusArea.dateMenu;
weather = new Weather.WeatherClient();
network = Main.panel._network;
networkIcon = network ? network._primaryIndicator : null;
panelWeather = new PanelWeather(weather, networkIcon);

topBox = new St.BoxLayout({
style_class: "clock",
});
if (panelWeather) return

topBox.add_child(panelWeather);
statusArea = Main.panel.statusArea;
dateMenu = statusArea.dateMenu;
weather = new Weather.WeatherClient();
network = Main.panel._network;
networkIcon = network ? network._primaryIndicator : null;
panelWeather = new PanelWeather(weather, networkIcon);

dateMenu._clockDisplay
.get_parent()
.replace_child(dateMenu._clockDisplay, topBox);
this._topBox = new St.BoxLayout({
style_class: "clock",
});

dateMenu._clockDisplay.remove_style_class_name("clock");
topBox.add_child(dateMenu._clockDisplay);
}
dateMenu._clockDisplay.remove_style_class_name("clock");
dateMenu._clockDisplay
.get_parent()
.replace_child(dateMenu._clockDisplay, this._topBox);


this._settings = this.getSettings();
this._positionChangeListener = this._settings.connect('changed::weather-after-clock', () => this._addWidget());
this._addWidget();
}

disable() {
topBox.remove_child(dateMenu._clockDisplay);
dateMenu._clockDisplay.add_style_class_name("clock");
this._positionChangeListener = null
this._topBox.remove_child(dateMenu._clockDisplay);
dateMenu._clockDisplay.remove_style_class_name("label-right-margin");
dateMenu._clockDisplay.remove_style_class_name("label-left-margin");

topBox
this._topBox
.get_parent()
.replace_child(topBox, dateMenu._clockDisplay);
.replace_child(this._topBox, dateMenu._clockDisplay);

topBox = null;
this._topBox = null;
weather = null;
if (panelWeather) {
panelWeather.destroy();
panelWeather = null;
}
}

_addWidget() {
this._topBox.remove_child(dateMenu._clockDisplay);
this._topBox.remove_child(panelWeather);
dateMenu._clockDisplay.remove_style_class_name("label-right-margin");
dateMenu._clockDisplay.remove_style_class_name("label-left-margin");

isWeatherAfterClock = this._settings.get_boolean('weather-after-clock');
if (isWeatherAfterClock) {
this._topBox.add_child(dateMenu._clockDisplay);
this._topBox.add_child(panelWeather);
dateMenu._clockDisplay.add_style_class_name("label-right-margin");

return
}

this._topBox.add_child(panelWeather);
this._topBox.add_child(dateMenu._clockDisplay);
dateMenu._clockDisplay.add_style_class_name("label-left-margin");
}
}

const PanelWeather = GObject.registerClass(
Expand Down Expand Up @@ -95,10 +127,9 @@ const PanelWeather = GObject.registerClass(

this._label = new St.Label({
y_align: Clutter.ActorAlign.CENTER,
style_class: "clock-label",
style_class: "clock-label weather_label",
});
this._label.clutter_text.y_align = Clutter.ActorAlign.CENTER;
this._label.add_style_class_name("weather_label");

this.add_child(this._label);

Expand Down
7 changes: 5 additions & 2 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
"uuid": "[email protected]",
"name": "Weather O'Clock",
"description": "Display the current weather inside the pill next to the clock. GNOME Weather is required for this extension to work.",
"shell-version": ["46"],
"shell-version": [
"47"
],
"url": "https://github.com/CleoMenezesJr/weather-oclock",
"original-author": "[email protected]",
"donations": {
"github": "CleoMenezesJr",
"kofi": "cleomenezesjr",
"paypal": "CleoMenezesJr"
},
"version-name": "46.2"
"settings-schema": "org.gnome.shell.extensions.weather-oclock",
"version-name": "47.0"
}
45 changes: 45 additions & 0 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/****************************************************************************
** Weather O'Clock extension for GNOME Shell 45+
** Copyright (C) 2024 Cleo Menezes Jr.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <https://www.gnu.org/licenses/>.
****************************************************************************/
"use strict";

import Gtk from "gi://Gtk";
import Gio from "gi://Gio";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";

export default class WeatherOClockPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
window._settings = this.getSettings();
window.set_default_size(360, 200);

const builder = new Gtk.Builder();
builder.add_from_file(`${this.path}/prefs.ui`);

const weatherAfterClock = builder.get_object("WeatherAfterClock");
weatherAfterClock.set_active(window._settings.get_boolean("weather-after-clock"));

window._settings.bind(
"weather-after-clock",
weatherAfterClock,
"active",
Gio.SettingsBindFlags.DEFAULT,
);

const page = builder.get_object("MainWidget");
window.add(page);
}
}
24 changes: 24 additions & 0 deletions [email protected]/prefs.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="auto-activities">
<object class="AdwPreferencesPage" id="MainWidget">
<property name="title" translatable="yes">Preferences</property>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">General</property>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Weather After Clock</property>
<property name="subtitle" translatable="yes">Widget to the right of the clock</property>
<property name="activatable-widget">WeatherAfterClock</property>
<child>
<object class="GtkSwitch" id="WeatherAfterClock">
<property name="valign">center</property>
<property name="active">False</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.gnome.shell.extensions.weather-oclock"
path="/org/gnome/shell/extensions/weather-oclock/">
<key name="weather-after-clock" type="b">
<default>false</default>
</key>
</schema>
</schemalist>
9 changes: 8 additions & 1 deletion [email protected]/stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
.weather_label {
margin-right: 0.7em;
margin-left: 0.3em;
}

.label-right-margin {
margin-right: 0.7em;
}

.label-left-margin {
margin-left: 0.7em;
}

.custom-weather-icon-spacing {
padding: 0;
margin: 0;
Expand Down

0 comments on commit c7b9170

Please sign in to comment.