Skip to content

Commit

Permalink
port to gnome 45
Browse files Browse the repository at this point in the history
this drops backwards compatibility support due to esm imports
  • Loading branch information
jonian committed Oct 11, 2023
1 parent 60d3793 commit 825a5cc
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 124 deletions.
28 changes: 14 additions & 14 deletions dark-variant@hardpixel.eu/extension.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Shell = imports.gi.Shell
const Util = imports.misc.util
const ExtensionUtils = imports.misc.extensionUtils
import Shell from 'gi://Shell'
import * as Util from 'resource:///org/gnome/shell/misc/util.js'
import * as Ext from 'resource:///org/gnome/shell/extensions/extension.js'

function getXid(win) {
const desc = win.get_description()
Expand Down Expand Up @@ -56,8 +56,8 @@ class ShellApp {
}

class DarkVariant {
constructor() {
this.settings = ExtensionUtils.getSettings()
constructor(ext) {
this.settings = ext.getSettings()
this.appSystem = Shell.AppSystem.get_default()
this.appsList = new Map()

Expand Down Expand Up @@ -90,14 +90,14 @@ class DarkVariant {
}
}

let darkVariant = null

function enable() {
darkVariant = new DarkVariant()
darkVariant.activate()
}
export default class Extension extends Ext.Extension {
enable() {
this.darkVariant = new DarkVariant(this)
this.darkVariant.activate()
}

function disable() {
darkVariant.destroy()
darkVariant = null
disable() {
this.darkVariant.destroy()
this.darkVariant = null
}
}
2 changes: 1 addition & 1 deletion dark-variant@hardpixel.eu/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"shell-version": ["42", "43", "44"],
"shell-version": ["45"],
"uuid": "dark-variant@hardpixel.eu",
"url": "https://github.com/hardpixel/dark-variant",
"settings-schema": "org.gnome.shell.extensions.dark-variant",
Expand Down
234 changes: 125 additions & 109 deletions dark-variant@hardpixel.eu/prefs.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,121 @@
const GLib = imports.gi.GLib
const GObject = imports.gi.GObject
const Adw = imports.gi.Adw
const Gtk = imports.gi.Gtk
const Gio = imports.gi.Gio
const Pango = imports.gi.Pango
const ExtensionUtils = imports.misc.extensionUtils

var DarkVariantSettings = GObject.registerClass(
class DarkVariantPrefsWidget extends Adw.PreferencesGroup {
_init() {
super._init({
title: 'Applications'
})

this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
css_classes: ['boxed-list']
})

this.add(this._list)

this._list.append(new NewAppRow())
this._list.connect('row-activated', this._onAddActivated.bind(this))

this._settings = ExtensionUtils.getSettings()
this._changeId = this._settings.connect(
'changed::applications',
this._onSync.bind(this)
)

this._onSync()
}
import GLib from 'gi://GLib'
import GObject from 'gi://GObject'
import Adw from 'gi://Adw'
import Gtk from 'gi://Gtk'
import Gio from 'gi://Gio'
import Pango from 'gi://Pango'
import * as Prefs from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'

class DarkVariantPrefsWidget extends Adw.PreferencesGroup {
static {
GObject.registerClass(this)
}

_onAddActivated() {
const dialog = new NewAppDialog(this.get_root())
dialog.show()
}
constructor() {
super({
title: 'Applications'
})

_onSync() {
const oldApps = [...this._list].filter(row => !!row.id)
const newApps = this._settings.get_strv('applications')
.map(id => Gio.DesktopAppInfo.new(id))
.filter(appInfo => !!appInfo)
this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
css_classes: ['boxed-list']
})

this._settings.block_signal_handler(this._changeId)
this.add(this._list)

newApps.forEach((appInfo, index) => {
const id = appInfo.get_id()
this._list.append(new NewAppRow())
this._list.connect('row-activated', this._onAddActivated.bind(this))

if (!oldApps.some(row => row.id === id)) {
this._list.insert(new AppRow(appInfo), index)
}
})
this._settings = preferences.getSettings()
this._changeId = this._settings.connect(
'changed::applications',
this._onSync.bind(this)
)

oldApps.forEach((row, index) => {
if (!newApps.some(appInfo => row.id === appInfo.get_id())) {
this._list.remove(row)
}
})
this._onSync()
}

this._settings.unblock_signal_handler(this._changeId)
}
_onAddActivated() {
const dialog = new NewAppDialog(this.get_root())
dialog.show()
}
)

const AppRow = GObject.registerClass(
class AppRow extends Adw.ActionRow {
_init(appInfo) {
super._init({
activatable: false,
title: appInfo.get_display_name()
})

this._appInfo = appInfo
this._settings = ExtensionUtils.getSettings()

const icon = new Gtk.Image({
css_classes: ['icon-dropshadow'],
gicon: appInfo.get_icon(),
pixel_size: 32
})

this.add_prefix(icon)

const button = new Gtk.Button({
icon_name: 'edit-delete-symbolic',
has_frame: false,
valign: Gtk.Align.CENTER
})

button.connect('clicked', this._onRemoveClicked.bind(this))
this.add_suffix(button)
}

get id() {
return this._appInfo.get_id()
}
_onSync() {
const oldApps = [...this._list].filter(row => !!row.id)
const newApps = this._settings.get_strv('applications')
.map(id => Gio.DesktopAppInfo.new(id))
.filter(appInfo => !!appInfo)

_onRemoveClicked() {
const current = this._settings.get_strv('applications')
const updated = current.filter(app => app !== this.id)
this._settings.block_signal_handler(this._changeId)

this._settings.set_strv('applications', updated)
}
newApps.forEach((appInfo, index) => {
const id = appInfo.get_id()

if (!oldApps.some(row => row.id === id)) {
this._list.insert(new AppRow(appInfo), index)
}
})

oldApps.forEach((row, index) => {
if (!newApps.some(appInfo => row.id === appInfo.get_id())) {
this._list.remove(row)
}
})

this._settings.unblock_signal_handler(this._changeId)
}
}

class AppRow extends Adw.ActionRow {
static {
GObject.registerClass(this)
}

constructor(appInfo) {
super({
activatable: false,
title: appInfo.get_display_name()
})

this._appInfo = appInfo
this._settings = preferences.getSettings()

const icon = new Gtk.Image({
css_classes: ['icon-dropshadow'],
gicon: appInfo.get_icon(),
pixel_size: 32
})

this.add_prefix(icon)

const button = new Gtk.Button({
icon_name: 'edit-delete-symbolic',
has_frame: false,
valign: Gtk.Align.CENTER
})

button.connect('clicked', this._onRemoveClicked.bind(this))
this.add_suffix(button)
}

get id() {
return this._appInfo.get_id()
}

_onRemoveClicked() {
const current = this._settings.get_strv('applications')
const updated = current.filter(app => app !== this.id)

this._settings.set_strv('applications', updated)
}
)
}

const NewAppRow = GObject.registerClass(
class NewAppRow extends Gtk.ListBoxRow {
_init() {
static {
GObject.registerClass(this)
}

constructor() {
const icon = new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
Expand All @@ -118,22 +125,25 @@ class NewAppRow extends Gtk.ListBoxRow {
margin_end: 12
})

super._init({
super({
child: icon
})
}
})
}

const NewAppDialog = GObject.registerClass(
class NewAppDialog extends Gtk.AppChooserDialog {
_init(parent) {
super._init({
static {
GObject.registerClass(this)
}

constructor(parent) {
super({
transient_for: parent,
modal: true
})

this._widget = this.get_widget()
this._settings = ExtensionUtils.getSettings()
this._settings = preferences.getSettings()

this._widget.get_parent().set({
margin_top: 5,
Expand Down Expand Up @@ -184,12 +194,18 @@ class NewAppDialog extends Gtk.AppChooserDialog {

this.destroy()
}
})

function init() {
ExtensionUtils.initTranslations()
}

function buildPrefsWidget() {
return new DarkVariantSettings()
let preferences = null

export default class Preferences extends Prefs.ExtensionPreferences {
fillPreferencesWindow(window) {
preferences = this

const page = Adw.PreferencesPage.new()
const pref = new DarkVariantPrefsWidget()

page.add(pref)
window.add(page)
}
}

0 comments on commit 825a5cc

Please sign in to comment.