Skip to content

Commit 1cf2712

Browse files
committed
port to gnome 45
this drops backwards compatibility support due to esm imports fix #16
1 parent 3331367 commit 1cf2712

File tree

8 files changed

+406
-1085
lines changed

8 files changed

+406
-1085
lines changed

systemd-manager@hardpixel.eu/convenience.js

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
1-
const GObject = imports.gi.GObject
2-
const Main = imports.ui.main
3-
const PanelMenu = imports.ui.panelMenu
4-
const PopupMenu = imports.ui.popupMenu
5-
const St = imports.gi.St
6-
const Me = imports.misc.extensionUtils.getCurrentExtension()
7-
const Convenience = Me.imports.convenience
8-
const PopupServiceItem = Me.imports.widgets.PopupServiceItem
9-
const PopupSettingsItem = Me.imports.widgets.PopupSettingsItem
10-
const Utils = Me.imports.utils
11-
12-
const SystemdManager = GObject.registerClass(
13-
class SystemdManager extends PanelMenu.Button {
14-
_init() {
15-
this._settings = Convenience.getSettings()
16-
this._settings.connect('changed', () => this._refresh())
17-
18-
super._init(0.2, null, false)
19-
20-
const icon = new St.Icon({
21-
icon_name: 'system-run-symbolic',
22-
style_class: 'system-status-icon'
23-
})
1+
import GObject from 'gi://GObject'
2+
import St from 'gi://St'
3+
import * as Ext from 'resource:///org/gnome/shell/extensions/extension.js'
4+
import * as Main from 'resource:///org/gnome/shell/ui/main.js'
5+
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js'
6+
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js'
7+
import * as Utils from './utils.js'
8+
import { PopupServiceItem, PopupSettingsItem } from './widgets.js'
9+
10+
class SystemdManager extends PanelMenu.Button {
11+
static {
12+
GObject.registerClass(this)
13+
}
2414

25-
this.add_actor(icon)
26-
this.refresh()
15+
constructor(ext) {
16+
super(0.2, null, false)
2717

28-
this.menu.connect('open-state-changed', () => {
29-
if (this.menu.isOpen) {
30-
this.refresh()
31-
}
32-
})
33-
}
18+
this._settings = ext.getSettings()
19+
this._settings.connect('changed', () => this.refresh(ext))
3420

35-
refresh() {
36-
this.menu.removeAll()
21+
const icon = new St.Icon({
22+
icon_name: 'system-run-symbolic',
23+
style_class: 'system-status-icon'
24+
})
3725

38-
const entries = this._settings.get_strv('systemd')
39-
const showAdd = this._settings.get_boolean('show-add')
40-
const showRestart = this._settings.get_boolean('show-restart')
41-
const showMask = this._settings.get_boolean('show-mask')
42-
const cmdMethod = this._settings.get_enum('command-method')
26+
this.add_actor(icon)
27+
this.refresh(ext)
4328

44-
const services = entries.map(data => JSON.parse(data))
45-
const fetchStates = (type, flag) => Utils.getServicesState(
46-
type, flag, services.filter(ob => ob.type == type).map(ob => ob.service)
47-
)
29+
this.menu.connect('open-state-changed', () => {
30+
if (this.menu.isOpen) {
31+
this.refresh(ext)
32+
}
33+
})
34+
}
4835

49-
const stateTypes = ['system', 'user']
50-
const activeStates = stateTypes.reduce(
51-
(all, type) => ({ ...all, [type]: fetchStates(type, 'is-active') }), {}
52-
)
36+
refresh(ext) {
37+
this.menu.removeAll()
5338

54-
const enabledStates = stateTypes.reduce(
55-
(all, type) => ({...all, [type]: fetchStates(type, 'is-enabled')}), {}
56-
)
39+
const entries = this._settings.get_strv('systemd')
40+
const showAdd = this._settings.get_boolean('show-add')
41+
const showRestart = this._settings.get_boolean('show-restart')
42+
const showMask = this._settings.get_boolean('show-mask')
43+
const cmdMethod = this._settings.get_enum('command-method')
5744

58-
services.forEach(({ type, name, service }) => {
59-
const isActive = activeStates[type][service]
60-
const isEnabled = enabledStates[type][service]
45+
const services = entries.map(data => JSON.parse(data))
46+
const fetchStates = (type, flag) => Utils.getServicesState(
47+
type, flag, services.filter(ob => ob.type == type).map(ob => ob.service)
48+
)
6149

62-
const entry = new PopupServiceItem(name, { isActive, isEnabled, showRestart, showMask })
63-
this.menu.addMenuItem(entry)
50+
const stateTypes = ['system', 'user']
51+
const activeStates = stateTypes.reduce(
52+
(all, type) => ({ ...all, [type]: fetchStates(type, 'is-active') }), {}
53+
)
6454

65-
entry.connect('toggled', (actor, active) => {
66-
const action = active ? 'start' : 'stop'
67-
Utils.runServiceAction(cmdMethod, action, type, service)
68-
})
55+
const enabledStates = stateTypes.reduce(
56+
(all, type) => ({...all, [type]: fetchStates(type, 'is-enabled')}), {}
57+
)
6958

70-
entry.connect('restarted', () => {
71-
Utils.runServiceAction(cmdMethod, 'restart', type, service)
72-
this.menu.close()
73-
})
59+
services.forEach(({ type, name, service }) => {
60+
const isActive = activeStates[type][service]
61+
const isEnabled = enabledStates[type][service]
7462

75-
entry.connect('mask-toggled', (actor, masked) => {
76-
const action = masked ? 'unmask' : 'mask'
77-
Utils.runServiceAction(cmdMethod, action, type, service)
63+
const entry = new PopupServiceItem(name, { isActive, isEnabled, showRestart, showMask })
64+
this.menu.addMenuItem(entry)
7865

79-
this.menu.close()
80-
})
66+
entry.connect('toggled', (actor, active) => {
67+
const action = active ? 'start' : 'stop'
68+
Utils.runServiceAction(cmdMethod, action, type, service)
8169
})
8270

83-
if (showAdd && entries.length > 0) {
84-
const separator = new PopupMenu.PopupSeparatorMenuItem()
85-
this.menu.addMenuItem(separator)
86-
}
71+
entry.connect('restarted', () => {
72+
Utils.runServiceAction(cmdMethod, 'restart', type, service)
73+
this.menu.close()
74+
})
8775

88-
if (showAdd) {
89-
const settings = new PopupSettingsItem('Add services')
90-
this.menu.addMenuItem(settings)
91-
}
92-
}
93-
}
94-
)
76+
entry.connect('mask-toggled', (actor, masked) => {
77+
const action = masked ? 'unmask' : 'mask'
78+
Utils.runServiceAction(cmdMethod, action, type, service)
9579

96-
let servicesManager = null
80+
this.menu.close()
81+
})
82+
})
9783

98-
function enable() {
99-
servicesManager = new SystemdManager()
100-
Main.panel.addToStatusArea('systemdManager', servicesManager)
84+
if (showAdd && entries.length > 0) {
85+
const separator = new PopupMenu.PopupSeparatorMenuItem()
86+
this.menu.addMenuItem(separator)
87+
}
88+
89+
if (showAdd) {
90+
const settings = new PopupSettingsItem(ext, 'Add services')
91+
this.menu.addMenuItem(settings)
92+
}
93+
}
10194
}
10295

103-
function disable() {
104-
servicesManager.destroy()
105-
servicesManager = null
96+
export default class Extension extends Ext.Extension {
97+
enable() {
98+
this.button = new SystemdManager(this)
99+
Main.panel.addToStatusArea('systemdManager', this.button)
100+
}
101+
102+
disable() {
103+
this.button.destroy()
104+
this.button = null
105+
}
106106
}

systemd-manager@hardpixel.eu/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"shell-version": ["3.32", "3.34", "3.36", "3.38", "40", "41", "42", "43", "44"],
2+
"shell-version": ["45"],
33
"uuid": "systemd-manager@hardpixel.eu",
44
"url": "https://github.com/hardpixel/systemd-manager",
55
"settings-schema": "org.gnome.shell.extensions.systemd-manager",

0 commit comments

Comments
 (0)