Skip to content

Commit

Permalink
Merge pull request #35 from stuarthayhurst/gnome45
Browse files Browse the repository at this point in the history
GNOME 45 support
  • Loading branch information
stuarthayhurst committed Aug 16, 2023
2 parents 0f16286 + efa46a5 commit c5a641c
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 562 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,3 @@ jobs:
with:
name: [email protected]
path: build/[email protected]

- name: Upload extension bundle to release
uses: actions/github-script@v6
if: startsWith(github.ref, 'refs/tags/v')
with:
script: |
const fs = require('fs');
const tag = context.ref.replace('refs/tags/', '');
//Get release for this tag
const release = await github.rest.repos.getReleaseByTag({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
tag
});
//Upload
const bundleName = '[email protected]';
await github.rest.repos.uploadReleaseAsset({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
release_id: release.data.id,
name: bundleName,
data: await fs.readFileSync('build/' + bundleName)
});
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ BUNDLE_PATH = "$(BUILD_DIR)/$(UUID).shell-extension.zip"

build: clean
@mkdir -p $(BUILD_DIR)
glib-compile-schemas --strict extension/schemas --targetdir $(BUILD_DIR)
$(MAKE) package
package:
@mkdir -p $(BUILD_DIR)
Expand All @@ -21,8 +20,7 @@ package:
--podir=po \
--extra-source=../LICENSE.txt \
--extra-source=../docs/CHANGELOG.md \
--extra-source=ui/ \
--extra-source=lib/ \
--extra-source=ui/gtk4/ \
-o ../$(BUILD_DIR)/
check:
@if [[ ! -f $(BUNDLE_PATH) ]]; then \
Expand All @@ -40,8 +38,7 @@ release:
$(MAKE) build
$(MAKE) check
translations:
@./scripts/update-pot.sh
@./scripts/update-po.sh -a
@BUILD_DIR=$(BUILD_DIR) ./scripts/update-po.sh -a
gtk4:
@$(MAKE) $(UI_FILES)
$(UI_FILES):
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Privacy Quick Settings GNOME Extension
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?hosted_button_id=G2REEPPNZK9GN)
- Add privacy quick settings to the system menu for quick access to privacy settings in GNOME
- Supports GNOME 3.38+, earlier versions are untested
- Supports GNOME 45+
- Get the extension from [here](https://extensions.gnome.org/extension/4491/privacy-settings-menu/)
- This project is licensed under GPL 3.0
- Any donations are greatly appreciated :)
Expand All @@ -14,6 +14,11 @@
- Due to limitations in GNOME shell, only sandboxed (flatpak / snap) apps can be forced to respect privacy settings
- As long as the settings changed by the extension match the settings inside GNOME Settings (privacy section), the extension is behaving correctly

## Older versions:
- Support for older versions of GNOME can be found in branches
- Find the name of the branch thgat supports the target version, and install from there
- Alternatively, you can just use an older release or tag to install from

## Install the extension from releases:
- Extract the zip to `~/.local/share/gnome-shell-extensions/PrivacyMenu@stuarthayhurst/`
- Alternatively: `gnome-extensions install "[email protected]" --force`
Expand Down Expand Up @@ -43,7 +48,6 @@
## Install dependencies:
- gettext
- gnome-extensions
- libglib2.0-bin

## Build dependencies: (Only required if running `make release`)
- `All install dependencies`
Expand Down
184 changes: 76 additions & 108 deletions extension/extension.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
/* exported init enable disable */

//Local extension imports
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { ExtensionHelper } = Me.imports.lib;
const ShellVersion = parseFloat(imports.misc.config.PACKAGE_VERSION);
/* exported ExtensionManager */

//Main imports
const { St, Gio, GObject } = imports.gi;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;

const QuickSettings = ShellVersion >= 43 ? imports.ui.quickSettings : null;
const QuickSettingsMenu = ShellVersion >= 43 ? imports.ui.main.panel.statusArea.quickSettings : null;

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

function init() {
ExtensionUtils.initTranslations();
}
import St from 'gi://St';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';

function enable() {
//Create new extension
privacyMenu = new Extension();
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';

//Create menu
privacyMenu.initMenu();
}
import * as QuickSettings from 'resource:///org/gnome/shell/ui/quickSettings.js';
const QuickSettingsMenu = Main.panel.statusArea.quickSettings;

function disable() {
//Disconnect listeners, then destroy the menu and class
privacyMenu.disconnectListeners();
privacyMenu.destroyMenu();
privacyMenu = null;
}
//Extension system imports
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';

//Custom PopupMenuItem with an icon, label and switch
const PrivacySettingImageSwitchItem = GObject.registerClass(
Expand Down Expand Up @@ -69,6 +48,16 @@ const PrivacyIndicator = GObject.registerClass(
this._locationSettings = new Gio.Settings({schema: 'org.gnome.system.location'});
}

_resetSettings() {
let privacySettings = new Gio.Settings({schema: 'org.gnome.desktop.privacy'});
let locationSettings = new Gio.Settings({schema: 'org.gnome.system.location'});

//Reset the settings
locationSettings.reset('enabled');
privacySettings.reset('disable-camera');
privacySettings.reset('disable-microphone');
}

addEntries() {
this.menu.addMenuItem(new PopupMenu.PopupMenuItem(
_('Privacy Settings'),
Expand Down Expand Up @@ -108,31 +97,23 @@ const PrivacyIndicator = GObject.registerClass(
//Create a submenu for the reset option, to prevent a misclick
let subMenu = new PopupMenu.PopupSubMenuMenuItem(_('Reset settings'), true);
subMenu.icon.icon_name = 'edit-delete-symbolic';
subMenu.menu.addAction(_('Reset to defaults'), ExtensionHelper.resetSettings, null);
subMenu.menu.addAction(_('Reset to defaults'), this._resetSettings, null);

this.menu.addMenuItem(subMenu);
}
}
);

//On GNOME 43+ create a class for privacy quick settings toggles
const PrivacyQuickToggle = ShellVersion >= 43 ? GObject.registerClass(
//Class for individual privacy quick settings toggles
const PrivacyQuickToggle = GObject.registerClass(
class PrivacyQuickToggle extends QuickSettings.QuickToggle {
_init(settingName, settingIcon, settingSchema, settingKey, settingBindFlag) {
//Set up the quick setting toggle
if (ShellVersion >= 44) {
super._init({
title: settingName,
iconName: settingIcon,
toggleMode: true,
});
} else {
super._init({
label: settingName,
iconName: settingIcon,
toggleMode: true,
});
}
super._init({
title: settingName,
iconName: settingIcon,
toggleMode: true,
});

//GSettings access
this._settings = new Gio.Settings({schema: settingSchema});
Expand All @@ -146,26 +127,18 @@ const PrivacyQuickToggle = ShellVersion >= 43 ? GObject.registerClass(
);
}
}
) : null;
);

//On GNOME 43+ create a class for the privacy quick settings group
const PrivacyQuickGroup = ShellVersion >= 43 ? GObject.registerClass(
//Class for the privacy quick settings group
const PrivacyQuickGroup = GObject.registerClass(
class PrivacyQuickGroup extends QuickSettings.QuickMenuToggle {
_init(useQuickSubtitle) {
//Set up the quick setting toggle
if (ShellVersion >= 44) {
super._init({
title: _('Privacy'),
iconName: 'preferences-system-privacy-symbolic',
toggleMode: false,
});
} else {
super._init({
label: _('Privacy'),
iconName: 'preferences-system-privacy-symbolic',
toggleMode: false,
});
}
super._init({
title: _('Privacy'),
iconName: 'preferences-system-privacy-symbolic',
toggleMode: false,
});

//Set a menu header
this.menu.setHeader('preferences-system-privacy-symbolic', _('Privacy Settings'))
Expand Down Expand Up @@ -226,10 +199,8 @@ const PrivacyQuickGroup = ShellVersion >= 43 ? GObject.registerClass(
}

_updateSubtitle() {
//Not supported below GNOME 44
if (ShellVersion < 44) {
return;
} else if (!this._useQuickSubtitle) {
//Skip if disabled
if (!this._useQuickSubtitle) {
return;
}

Expand Down Expand Up @@ -263,9 +234,8 @@ const PrivacyQuickGroup = ShellVersion >= 43 ? GObject.registerClass(
this._settingsInfo[i][0].disconnect(signalId);
});
}

}
) : null;
);

class QuickSettingsManager {
constructor() {
Expand All @@ -279,28 +249,18 @@ class QuickSettingsManager {
];

//Create a quick setting toggle for each privacy setting
quickSettingsInfo.forEach((quickSettingInfo) => {
quickSettingsInfo.forEach((quickSettingInfo, i) => {
this._quickSettingToggles.push(
new PrivacyQuickToggle(
quickSettingInfo[0],
quickSettingInfo[1],
quickSettingInfo[2],
quickSettingInfo[3],
quickSettingInfo[0], quickSettingInfo[1],
quickSettingInfo[2], quickSettingInfo[3],
quickSettingInfo[4]
)
);
});

//Add the toggles to the system menu
QuickSettingsMenu._addItems(this._quickSettingToggles);

//Place the toggles above the background apps entry
if (ShellVersion >= 44) {
this._quickSettingToggles.forEach((item) => {
QuickSettingsMenu.menu._grid.set_child_below_sibling(item,
QuickSettingsMenu._backgroundApps.quickSettingsItems[0]);
});
}
//Add the toggle to the system menu
QuickSettingsMenu.addExternalIndicator(this._quickSettingToggles[i]);
});
}

clean() {
Expand All @@ -316,16 +276,9 @@ class QuickSettingsManager {

class QuickGroupManager {
constructor(useQuickSubtitle) {
//Create quick settings group and add to the system menu
this._quickSettingsGroup = new PrivacyQuickGroup(useQuickSubtitle);

//Add the toggles to the system menu
QuickSettingsMenu._addItems([this._quickSettingsGroup]);

//Place the toggles above the background apps entry
if (ShellVersion >= 44) {
QuickSettingsMenu.menu._grid.set_child_below_sibling(this._quickSettingsGroup,
QuickSettingsMenu._backgroundApps.quickSettingsItems[0]);
}
QuickSettingsMenu.addExternalIndicator(this._quickSettingsGroup);
}

clean() {
Expand All @@ -350,7 +303,7 @@ class IndicatorSettingsManager {
}

//Add to panel
Main.panel.addToStatusArea(Me.metadata.uuid, this._indicator, offset);
Main.panel.addToStatusArea('privacy-menu', this._indicator, offset);
}

clean() {
Expand All @@ -361,10 +314,27 @@ class IndicatorSettingsManager {
}
}

class Extension {
constructor() {
export default class ExtensionManager extends Extension {
enable() {
//Create new extension
this._privacyMenu = new PrivacyExtension(this.getSettings());

//Create menu
this._privacyMenu.initMenu();
}

disable() {
//Disconnect listeners, then destroy the menu and class
this._privacyMenu.disconnectListeners();
this._privacyMenu.destroyMenu();
this._privacyMenu = null;
}
}

class PrivacyExtension {
constructor(extensionSettings) {
this._privacyManager = null;
this._extensionSettings = ExtensionUtils.getSettings();
this._extensionSettings = extensionSettings;
}

disconnectListeners() {
Expand All @@ -373,17 +343,15 @@ class Extension {

_decideMenuType() {
/*
- Return 'quick-toggles' if running GNOME 43+ and quick settings are enabled
- If quick settings grouping is enabled, return 'quick-group' instead
- Otherwise return 'indiactors'
- Return 'quick-toggles' if quick settings are enabled
- If quick settings grouping is also enabled, return 'quick-group' instead
- Otherwise return 'indicators'
*/
if (this._extensionSettings.get_boolean('use-quick-settings')) {
if (ShellVersion >= 43) {
if (this._extensionSettings.get_boolean('group-quick-settings')) {
return 'quick-group';
}
return 'quick-toggles';
if (this._extensionSettings.get_boolean('group-quick-settings')) {
return 'quick-group';
}
return 'quick-toggles';
}

return 'indicator';
Expand Down
Loading

0 comments on commit c5a641c

Please sign in to comment.