Skip to content

Commit

Permalink
Review problems
Browse files Browse the repository at this point in the history
  • Loading branch information
AzzamAlsharafi committed Sep 10, 2022
1 parent 9721709 commit ee5a187
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 72 deletions.
31 changes: 31 additions & 0 deletions aggregateMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const GObject = imports.gi.GObject;
const PanelMenu = imports.ui.panelMenu;
const Main = imports.ui.main;

const AggregateMenu = Main.panel.statusArea.aggregateMenu;

const SystemMenu = GObject.registerClass(
class SystemMenu extends PanelMenu.SystemIndicator {

_init() {
super._init();

// Create extension's sub menu
this.subMenu = new PopupMenu.PopupSubMenuMenuItem(Me.metadata.name, true);
this.subMenu.icon.gicon = extensionIcon;

// Places the extension's sub menu after the battery sub menu if it exists,
// otherwise places the extension's sub menu at the first spot. (Change later? First spot might be bad idea)
const menuItems = AggregateMenu.menu._getMenuItems();
const subMenuIndex = AggregateMenu._power ? (menuItems.indexOf(AggregateMenu._power.menu) + 1) : 0;
AggregateMenu.menu.addMenuItem(this.subMenu, subMenuIndex);

addOptionsToMenu(this.subMenu.menu);
}

destroy() {
this.subMenu.destroy();
super.destroy();
}
}
);
87 changes: 15 additions & 72 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const optionsUtils = Me.imports.optionsUtils;

const extensionIcon = Gio.icon_new_for_string(Me.dir.get_path() + "/icons/controls-big-symbolic.svg");
// Each of GNOME 42 and GNOME 43 use a different system menu,
// that's why there are two classes for system menu.
// GNOME 42 uses AggregateMenu (SystemMenu),
// and GNOME 43 uses QuickSettings (QSystemMenu).
let SystemMenu = shellVersion < 43 ? Me.imports.aggregateMenu.SystemMenu : Me.imports.quickSettingsMenu.SystemMenu;

function init() {}

let extensionIcon = null;
let extensionMenu = null;
let settings = null;
let trayListener = null;

function enable() {
log("<here");
log(SystemMenu);
log("here>");

extensionIcon = Gio.icon_new_for_string(Me.dir.get_path() + "/icons/controls-big-symbolic.svg");

settings = ExtensionUtils.getSettings("org.gnome.shell.extensions.ideapad-controls");

updateLocation(settings);
Expand All @@ -44,6 +55,9 @@ function disable() {
extensionMenu = null;
}

extensionIcon = null;
settings = null;

optionsUtils.destroy();
}

Expand All @@ -61,77 +75,6 @@ function updateLocation(settings) {
}
}

// Each of GNOME 42 and GNOME 43 use a different system menu,
// that's why there are two classes for system menu.
// GNOME 42 uses AggregateMenu (SystemMenu),
// and GNOME 43 uses QuickSettings (QSystemMenu).
const SystemMenu = registerSystemMenu();

function registerSystemMenu() {
if (shellVersion < 43) { // GNOME 42
const AggregateMenu = Main.panel.statusArea.aggregateMenu;

return GObject.registerClass(
class SystemMenu extends PanelMenu.SystemIndicator {

_init() {
super._init();

// Create extension's sub menu
this.subMenu = new PopupMenu.PopupSubMenuMenuItem(Me.metadata.name, true);
this.subMenu.icon.gicon = extensionIcon;

// Places the extension's sub menu after the battery sub menu if it exists,
// otherwise places the extension's sub menu at the first spot. (Change later? First spot might be bad idea)
const menuItems = AggregateMenu.menu._getMenuItems();
const subMenuIndex = AggregateMenu._power ? (menuItems.indexOf(AggregateMenu._power.menu) + 1) : 0;
AggregateMenu.menu.addMenuItem(this.subMenu, subMenuIndex);

addOptionsToMenu(this.subMenu.menu);
}

destroy() {
this.subMenu.destroy();
super.destroy();
}
}
);
} else { // GNOME 43
const UIQuickSettings = imports.ui.quickSettings;
const QuickSettingsMenu = Main.panel.statusArea.quickSettings; // GNOME 43 System Menu

return GObject.registerClass(
class QSystemMenu extends UIQuickSettings.SystemIndicator {

_init() {
super._init();

// Create extension's sub menu
this.toggleMenu = new UIQuickSettings.QuickMenuToggle({label: "IdeaPad", // Not enough space for full name :(
gicon: extensionIcon});

this.toggleMenu.menu.setHeader(extensionIcon, Me.metadata.name);

// Since this "toggle" menu isn't being used as a toggle button
// clicking should just open the menu.
this.toggleMenu.connect("clicked", () => {
this.toggleMenu.menu.open();
})

QuickSettingsMenu.menu.addItem(this.toggleMenu);

addOptionsToMenu(this.toggleMenu.menu);
}

destroy() {
this.toggleMenu.destroy();
super.destroy();
}
}
);
}
}

const TrayMenu = GObject.registerClass(
class TrayMenu extends PanelMenu.Button {
_init() {
Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ echo "Packing extension..."
gnome-extensions pack ./ \
--extra-source=template.ui \
--extra-source=optionsUtils.js \
--extra-source=aggregateMenu.js \
--extra-source=quickSettingsMenu.js \
--extra-source=icons/ \
--extra-source=LICENSE.md \
--force \
Expand Down
37 changes: 37 additions & 0 deletions quickSettingsMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const GObject = imports.gi.GObject;
const Main = imports.ui.main;

const UIQuickSettings = imports.ui.quickSettings;
const QuickSettingsMenu = Main.panel.statusArea.quickSettings; // GNOME 43 System Menu

const SystemMenu = GObject.registerClass(
class QSystemMenu extends UIQuickSettings.SystemIndicator {

_init() {
super._init();

// Create extension's sub menu
this.toggleMenu = new UIQuickSettings.QuickMenuToggle({
label: "IdeaPad", // Not enough space for full name :(
gicon: extensionIcon
});

this.toggleMenu.menu.setHeader(extensionIcon, Me.metadata.name);

// Since this "toggle" menu isn't being used as a toggle button
// clicking should just open the menu.
this.toggleMenu.connect("clicked", () => {
this.toggleMenu.menu.open();
})

QuickSettingsMenu.menu.addItem(this.toggleMenu);

addOptionsToMenu(this.toggleMenu.menu);
}

destroy() {
this.toggleMenu.destroy();
super.destroy();
}
}
);

0 comments on commit ee5a187

Please sign in to comment.