Skip to content

Commit

Permalink
Merge pull request #8 from oqo0/dev
Browse files Browse the repository at this point in the history
Change icon status area position
  • Loading branch information
stuarthayhurst authored May 21, 2022
2 parents 0696c1e + 67cbdf8 commit 258cfdd
Show file tree
Hide file tree
Showing 13 changed files with 504 additions and 21 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/test-build-system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,43 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends git make optipng gettext gnome-shell
sudo apt-get install --no-install-recommends git make optipng gettext gnome-shell libglib2.0-bin
- name: Check assets are optimised and no extra files have been committed
run: |
# Check all assets are space optimised
make prune compress
# Clean up files (Shouldn't have to do anything)
make clean
# Fail if any files generated by last step that haven't been committed
if [ ! -z "$(git status --porcelain)" ]; then exit 1; fi
make prune compress COMPRESSLEVEL="-o0"
- name: Check translation generation works
run: |
make translations
git restore po/
- name: Test extension builds from a clean slate
run: |
make build
- name: Test extension is valid and able to be uploaded
run: |
make check
- name: Check no extra files have been committed
run: |
# Clean up files (Shouldn't have to do anything)
make clean
# Fail if any files generated by last step that haven't been committed
if [ ! -z "$(git status --porcelain)" ]; then exit 1; fi
- name: Check release workflow is functional
run: |
#Fake gtk4-builder-tool to echo to avoid errors due to no gtk4 packages
echo "echo \$@" | sudo tee /usr/bin/gtk4-builder-tool; sudo chmod +x /usr/bin/gtk4-builder-tool
make release
- name: Test extension installs
run: |
make install
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#Build files
PrivacyMenu@stuarthayhurst.shell-extension.zip
schemas/gschemas.compiled
locale/
po/*.po~

#Backups
*.po~
*.ui~
*.ui#
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
SHELL=bash
UUID=PrivacyMenu@stuarthayhurst
COMPRESSLEVEL=-o7
SHELL = bash
UUID = PrivacyMenu@stuarthayhurst
COMPRESSLEVEL = -o7

.PHONY: build check release translations prune compress install uninstall clean
.PHONY: build check release translations gtk4 prune compress install uninstall clean

build:
gnome-extensions pack --force --podir=po --extra-source=LICENSE.txt --extra-source=docs/CHANGELOG.md --extra-source=icons/ --extra-source=lib/
glib-compile-schemas schemas
gnome-extensions pack --force --podir=po --extra-source=LICENSE.txt --extra-source=docs/CHANGELOG.md --extra-source=icons/ --extra-source=ui --extra-source=lib/
check:
@if [[ ! -f "$(UUID).shell-extension.zip" ]]; then \
echo -e "WARNING! Extension zip couldn't be found"; exit 1; \
Expand All @@ -17,12 +18,15 @@ release:
sed -i "s| \"version\":.*| \"version\": $(VERSION)|g" metadata.json; \
fi
#Call other targets required to make a release
$(MAKE) gtk4
$(MAKE) translations prune compress
$(MAKE) build
$(MAKE) check
translations:
./scripts/update-pot.sh
./scripts/update-po.sh -a
gtk4:
gtk4-builder-tool simplify --3to4 ui/prefs.ui > ui/prefs-gtk4.ui
prune:
./scripts/clean-svgs.py
compress:
Expand All @@ -32,4 +36,5 @@ install:
uninstall:
gnome-extensions uninstall "$(UUID)"
clean:
rm -rf locale po/*.po~ "$(UUID).shell-extension.zip"
rm -rfv locale schemas/gschemas.compiled "$(UUID).shell-extension.zip"
rm -rfv po/*.po~ *.ui~ ui/*.ui~ ui/*.ui#
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
- `make translations`: Updates translations
- `make prune`: Removes rubbish from any .svgs in `docs/`
- `make compress`: Losslessly compresses any .pngs in `docs/`
- `make release`: Updated translations, then creates and checks an extension zip
- `make release`: Updates the UI, translations and icons, then creates and checks an extension zip

## Install dependencies:
- gettext
- gnome-extensions
- libglib2.0-bin

## Build dependencies: (Only required if running `make release`)
- `All install dependencies`
- sed (`make translations`)
- python3 (`make prune`)
- libgtk-4-bin (`make gtk4`)
- optipng (`make compress`)

## Want to help?
Expand Down
1 change: 1 addition & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- All translations can be refreshed with `make translations`
- Strings marked with `fuzzy` may need a better translation
- Blank strings need a translation added
- If changes to the strings in `ui/*.ui` were made, `make gtk4` should be run

## Documentation changes:
- British English should be used in documentation, as well as consistent styling
Expand Down
39 changes: 33 additions & 6 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function enable() {
privacyMenu = new Extension();

//Create menu
privacyMenu.createMenu();
privacyMenu.initMenu();
}

function disable() {
//Destroy the menu
privacyMenu.indicator.remove_all_children();
privacyMenu.indicator.destroy();
//Disconnect listeners, then destroy the indicator and class
privacyMenu.disconnectListeners();
privacyMenu.destroyMenu();
privacyMenu = null;
}

Expand Down Expand Up @@ -106,6 +106,22 @@ const PrivacyMenu = GObject.registerClass(
class Extension {
constructor() {
this.indicator = null;
this.extensionSettings = ExtensionUtils.getSettings();
}

disconnectListeners() {
this.extensionSettings.disconnect(this._settingsChangedSignal);
}

initMenu() {
//Create the indicator
this.createMenu();

//When settings change, recreate the indicator
this._settingsChangedSignal = this.extensionSettings.connect('changed', () => {
this.destroyMenu();
this.createMenu();
});
}

createMenu() {
Expand All @@ -115,8 +131,19 @@ class Extension {
//Add menu entries
this.indicator.addEntries();

//Add to panel with the correct position
let offset = Main.panel._rightBox.get_n_children() - 1;
//Get position to insert icon (left or right)
let offset = 0;
if (this.extensionSettings.get_boolean('move-icon-right')) {
offset = Main.panel._rightBox.get_n_children() - 1;
}

//Add to panel
Main.panel.addToStatusArea(Me.metadata.uuid, this.indicator, offset);
}

destroyMenu() {
//Destroy the indicator
this.indicator.remove_all_children();
this.indicator.destroy();
}
}
2 changes: 2 additions & 0 deletions lib/ExtensionHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//Functions to assist program operation
const { Gio } = imports.gi;

var shellVersion = parseFloat(imports.misc.config.PACKAGE_VERSION);

function resetSettings() {
let privacySettings = new Gio.Settings( {schema: 'org.gnome.desktop.privacy'} );
let locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location'} );
Expand Down
1 change: 1 addition & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Add a privacy menu to the top bar for quick access to privacy settings",
"uuid": "PrivacyMenu@stuarthayhurst",
"gettext-domain": "PrivacyMenu@stuarthayhurst",
"settings-schema": "org.gnome.shell.extensions.privacy-menu",
"url": "https://github.com/stuarthayhurst/privacy-menu-extension",
"shell-version": [
"3.38",
Expand Down
118 changes: 118 additions & 0 deletions prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* exported init fillPreferencesWindow buildPrefsWidget */

//Local extension imports
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { ExtensionHelper } = Me.imports.lib;
const ShellVersion = ExtensionHelper.shellVersion;

//Main imports
const { Gtk, Gio, GLib } = imports.gi;
const Adw = ShellVersion >= 42 ? imports.gi.Adw : null;

//Use _() for translations
const _ = imports.gettext.domain(Me.metadata.uuid).gettext;

var PrefsPages = class PrefsPages {
constructor() {
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.privacy-menu');

this._builder = new Gtk.Builder();
this._builder.set_translation_domain(Me.metadata.uuid);

this.createPreferences();
}

createPreferences() {
//Use different UI file for GNOME 40+ and 3.38
if (ShellVersion >= 40) {
this._builder.add_from_file(Me.path + '/ui/prefs-gtk4.ui');
} else {
this._builder.add_from_file(Me.path + '/ui/prefs.ui');
}

//Get the settings container widget
this.preferencesWidget = this._builder.get_object('main-prefs');

this.settingElements = {
'move-icon-switch': {
'settingKey': 'move-icon-right',
'bindProperty': 'active'
}
}

//Loop through settings toggles and dropdowns and bind together
Object.keys(this.settingElements).forEach((element) => {
this._settings.bind(
this.settingElements[element].settingKey, //GSettings key to bind to
this._builder.get_object(element), //GTK UI element to bind to
this.settingElements[element].bindProperty, //The property to share
Gio.SettingsBindFlags.DEFAULT
);
});
}
}

function init() {
ExtensionUtils.initTranslations();
}

//Create preferences window for GNOME 42+
function fillPreferencesWindow(window) {
//Create pages and widgets
let prefsPages = new PrefsPages();
let settingsPage = new Adw.PreferencesPage();
let settingsGroup = new Adw.PreferencesGroup();

//Build the settings page
settingsPage.set_title(_('Settings'));
settingsPage.set_icon_name('preferences-system-symbolic');
settingsGroup.add(prefsPages.preferencesWidget);
settingsPage.add(settingsGroup);

//Add the pages to the window
window.add(settingsPage);
}

//Create preferences window for GNOME 3.38-41
function buildPrefsWidget() {
let prefsPages = new PrefsPages();
let settingsWindow = new Gtk.ScrolledWindow();

//Use a stack to store pages
let pageStack = new Gtk.Stack();
pageStack.add_titled(prefsPages.preferencesWidget, 'settings', _('Settings'));

let pageSwitcher = new Gtk.StackSwitcher();
pageSwitcher.set_stack(pageStack);

//Add the stack to the scrolled window
if (ShellVersion >= 40) {
settingsWindow.set_child(pageStack);
} else {
settingsWindow.add(pageStack);
}

//Enable all elements differently for GNOME 40+ and 3.38
if (ShellVersion >= 40) {
settingsWindow.show();
} else {
settingsWindow.show_all();
}

//Modify top bar to add a page menu, when the window is ready
settingsWindow.connect('realize', () => {
let window = ShellVersion >= 40 ? settingsWindow.get_root() : settingsWindow.get_toplevel();
let headerBar = window.get_titlebar();

//Add page switching menu to header
if (ShellVersion >= 40) {
headerBar.set_title_widget(pageSwitcher);
} else {
headerBar.set_custom_title(pageSwitcher);
}
pageSwitcher.show();
});

return settingsWindow;
}
10 changes: 10 additions & 0 deletions schemas/org.gnome.shell.extensions.PrivacyMenu.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.gnome.shell.extensions.privacy-menu" path="/org/gnome/shell/extensions/privacy-menu/">
<key name="move-icon-right" type="b">
<default>true</default>
<summary>Move status icon right</summary>
<description>Force the icon to move to right side of the status area</description>
</key>
</schema>
</schemalist>
2 changes: 1 addition & 1 deletion scripts/update-pot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ xgettext --from-code=UTF-8 \
--copyright-holder="Stuart Hayhurst" \
--package-name="privacy-menu-extension" \
--output=po/messages.pot \
-- *.js lib/*.js
-- *.js lib/*.js ui/*.ui

#Replace some lines of the header with our own
sed -i '1s/.*/# <LANGUAGE> translation for the Privacy Settings Menu GNOME Shell Extension./' po/messages.pot
Expand Down
Loading

0 comments on commit 258cfdd

Please sign in to comment.