From 7f394453c8e269d9f6685defde928e5807c6f5df Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 20 Sep 2023 10:37:03 +0800 Subject: [PATCH] gnome 45, version 10 --- activate_gnome@isjerryxiao/extension.js | 24 +- activate_gnome@isjerryxiao/metadata.json | 8 +- activate_gnome@isjerryxiao/prefs.js | 315 ++++++++++++----------- 3 files changed, 171 insertions(+), 176 deletions(-) diff --git a/activate_gnome@isjerryxiao/extension.js b/activate_gnome@isjerryxiao/extension.js index 7724282..8067144 100644 --- a/activate_gnome@isjerryxiao/extension.js +++ b/activate_gnome@isjerryxiao/extension.js @@ -14,16 +14,15 @@ * along with this program. If not, see . * * SPDX-License-Identifier: GPL-3.0-or-later - * / -/* exported init */ -const St = imports.gi.St -const Main = imports.ui.main -const Mainloop = imports.mainloop -const ExtensionUtils = imports.misc.extensionUtils -const Me = ExtensionUtils.getCurrentExtension() + */ -class Extension { - constructor() { +import St from 'gi://St' +import * as Main from 'resource:///org/gnome/shell/ui/main.js' +import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js' + +export default class ActivateGnomeExtension extends Extension { + constructor(metadata) { + super(metadata) this.labels = [] this.settings = null this.handlers = [] @@ -65,7 +64,7 @@ class Extension { } enable() { - this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema']) + this.settings = this.getSettings() this.handlers.push({ owner: this.settings, id: this.settings.connect('changed', () => this.update()) @@ -90,8 +89,3 @@ class Extension { this.settings = null } } - -function init() { - log(`initializing ${Me.metadata.name}`) - return new Extension() -} diff --git a/activate_gnome@isjerryxiao/metadata.json b/activate_gnome@isjerryxiao/metadata.json index 4f2090d..cdd98fd 100644 --- a/activate_gnome@isjerryxiao/metadata.json +++ b/activate_gnome@isjerryxiao/metadata.json @@ -4,12 +4,8 @@ "uuid": "activate_gnome@isjerryxiao", "settings-schema": "org.gnome.shell.extensions.activate_gnome", "shell-version": [ - "40", - "41", - "42", - "43", - "44" + "45" ], - "version": 9, + "version": 10, "url": "https://github.com/isjerryxiao/gnome-shell-extension-activate-gnome" } diff --git a/activate_gnome@isjerryxiao/prefs.js b/activate_gnome@isjerryxiao/prefs.js index 3edd95f..64e1bde 100644 --- a/activate_gnome@isjerryxiao/prefs.js +++ b/activate_gnome@isjerryxiao/prefs.js @@ -1,158 +1,163 @@ -const Gio = imports.gi.Gio -const Gtk = imports.gi.Gtk +import Gio from 'gi://Gio' +import Gtk from 'gi://Gtk' +import Adw from 'gi://Adw' -const ExtensionUtils = imports.misc.extensionUtils -const Me = ExtensionUtils.getCurrentExtension() +import { ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js' -function init() { -} - -function buildPrefsWidget() { - this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema']) - - let prefsWidget = new Gtk.Box({ - orientation: Gtk.Orientation.VERTICAL, - halign: Gtk.Align.CENTER, - spacing: 6, - margin_top: 12, - margin_bottom: 12, - margin_start: 6, - margin_end: 6, - }) - - // line 1 - let label_line_1 = new Gtk.Label({ - label: 'Line 1', - margin_top: 6, - use_markup: true, - }) - prefsWidget.append(label_line_1) - - let entry_line_1 = new Gtk.Entry({ - margin_top: 6, - hexpand: true, - }) - entry_line_1.set_width_chars(30) - prefsWidget.append(entry_line_1) - - // line 2 - let label_line_2 = new Gtk.Label({ - label: 'Line 2', - margin_top: 6, - use_markup: true, - }) - prefsWidget.append(label_line_2) - - let entry_line_2 = new Gtk.Entry({ - margin_top: 6, - hexpand: true, - }) - entry_line_2.set_width_chars(30) - prefsWidget.append(entry_line_2) - - // line 2 vertical position - let label_line_2_vertical_position = new Gtk.Label({ - label: 'Vertical Position', - margin_top: 12, - use_markup: true, - }) - prefsWidget.append(label_line_2_vertical_position) - - let scale_line_2_vertical_position = new Gtk.Scale({ - adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}), - margin_top: 6, - draw_value: false, - digits: 4, - }) - prefsWidget.append(scale_line_2_vertical_position) - - // line 2 horizontal position - let label_line_2_horizontal_position = new Gtk.Label({ - label: 'Horizontal Position', - margin_top: 6, - use_markup: true, - }) - prefsWidget.append(label_line_2_horizontal_position) - - let scale_line_2_horizontal_position = new Gtk.Scale({ - adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}), - margin_top: 6, - draw_value: false, - digits: 4, - }) - prefsWidget.append(scale_line_2_horizontal_position) - - // line 1 text size - let label_line_1_text_size = new Gtk.Label({ - label: 'Line 1 Text Size', - margin_top: 12, - use_markup: true, - }) - prefsWidget.append(label_line_1_text_size) - - let spinbutton_line_1_text_size = new Gtk.SpinButton({ - adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}), - margin_top: 6, - numeric: true, - digits: 1, - }) - prefsWidget.append(spinbutton_line_1_text_size) - - // line 2 text size - let label_line_2_text_size = new Gtk.Label({ - label: 'Line 2 Text Size', - margin_top: 6, - use_markup: true, - }) - prefsWidget.append(label_line_2_text_size) - - let spinbutton_line_2_text_size = new Gtk.SpinButton({ - adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}), - margin_top: 6, - numeric: true, - digits: 1, - }) - prefsWidget.append(spinbutton_line_2_text_size) - - // opacity - let label_opacity = new Gtk.Label({ - label: 'Opacity', - margin_top: 6, - use_markup: true, - }) - prefsWidget.append(label_opacity) - - let scale_opacity = new Gtk.Scale({ - adjustment: new Gtk.Adjustment({lower: 0.1, upper: 255, step_increment: 0.1, page_increment: 1}), - margin_top: 6, - draw_value: false, - digits: 1, - }) - prefsWidget.append(scale_opacity) - - let button_reset = new Gtk.Button({ - label: 'reset', - margin_top: 12, - margin_bottom: 6, - }) - button_reset.connect('clicked', () => { - this.settings.reset('text-l1') - this.settings.reset('text-l2') - this.settings.reset('l2-vertical') - this.settings.reset('l2-horizontal') - this.settings.reset('size-l1') - this.settings.reset('size-l2') - this.settings.reset('opacity') - }) - prefsWidget.append(button_reset) - - this.settings.bind('text-l1', entry_line_1, 'text', Gio.SettingsBindFlags.DEFAULT) - this.settings.bind('text-l2', entry_line_2, 'text', Gio.SettingsBindFlags.DEFAULT) - this.settings.bind('l2-vertical', scale_line_2_vertical_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) - this.settings.bind('l2-horizontal', scale_line_2_horizontal_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) - this.settings.bind('size-l1', spinbutton_line_1_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) - this.settings.bind('size-l2', spinbutton_line_2_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) - this.settings.bind('opacity', scale_opacity.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) - - return prefsWidget +export default class ActivateGnomeExtensionPreferences extends ExtensionPreferences { + fillPreferencesWindow(window) { + const page = new Adw.PreferencesPage() + window.add(page) + + const group = new Adw.PreferencesGroup() + page.add(group) + + this.settings = this.getSettings() + + let prefsWidget = new Gtk.Box({ + orientation: Gtk.Orientation.VERTICAL, + halign: Gtk.Align.CENTER, + spacing: 6, + margin_top: 12, + margin_bottom: 12, + margin_start: 6, + margin_end: 6, + }) + + // line 1 + let label_line_1 = new Gtk.Label({ + label: 'Line 1', + margin_top: 6, + use_markup: true, + }) + prefsWidget.append(label_line_1) + + let entry_line_1 = new Gtk.Entry({ + margin_top: 6, + hexpand: true, + }) + entry_line_1.set_width_chars(30) + prefsWidget.append(entry_line_1) + + // line 2 + let label_line_2 = new Gtk.Label({ + label: 'Line 2', + margin_top: 6, + use_markup: true, + }) + prefsWidget.append(label_line_2) + + let entry_line_2 = new Gtk.Entry({ + margin_top: 6, + hexpand: true, + }) + entry_line_2.set_width_chars(30) + prefsWidget.append(entry_line_2) + + // line 2 vertical position + let label_line_2_vertical_position = new Gtk.Label({ + label: 'Vertical Position', + margin_top: 12, + use_markup: true, + }) + prefsWidget.append(label_line_2_vertical_position) + + let scale_line_2_vertical_position = new Gtk.Scale({ + adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}), + margin_top: 6, + draw_value: false, + digits: 4, + }) + prefsWidget.append(scale_line_2_vertical_position) + + // line 2 horizontal position + let label_line_2_horizontal_position = new Gtk.Label({ + label: 'Horizontal Position', + margin_top: 6, + use_markup: true, + }) + prefsWidget.append(label_line_2_horizontal_position) + + let scale_line_2_horizontal_position = new Gtk.Scale({ + adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}), + margin_top: 6, + draw_value: false, + digits: 4, + }) + prefsWidget.append(scale_line_2_horizontal_position) + + // line 1 text size + let label_line_1_text_size = new Gtk.Label({ + label: 'Line 1 Text Size', + margin_top: 12, + use_markup: true, + }) + prefsWidget.append(label_line_1_text_size) + + let spinbutton_line_1_text_size = new Gtk.SpinButton({ + adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}), + margin_top: 6, + numeric: true, + digits: 1, + }) + prefsWidget.append(spinbutton_line_1_text_size) + + // line 2 text size + let label_line_2_text_size = new Gtk.Label({ + label: 'Line 2 Text Size', + margin_top: 6, + use_markup: true, + }) + prefsWidget.append(label_line_2_text_size) + + let spinbutton_line_2_text_size = new Gtk.SpinButton({ + adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}), + margin_top: 6, + numeric: true, + digits: 1, + }) + prefsWidget.append(spinbutton_line_2_text_size) + + // opacity + let label_opacity = new Gtk.Label({ + label: 'Opacity', + margin_top: 6, + use_markup: true, + }) + prefsWidget.append(label_opacity) + + let scale_opacity = new Gtk.Scale({ + adjustment: new Gtk.Adjustment({lower: 0.1, upper: 255, step_increment: 0.1, page_increment: 1}), + margin_top: 6, + draw_value: false, + digits: 1, + }) + prefsWidget.append(scale_opacity) + + let button_reset = new Gtk.Button({ + label: 'reset', + margin_top: 12, + margin_bottom: 6, + }) + button_reset.connect('clicked', () => { + this.settings.reset('text-l1') + this.settings.reset('text-l2') + this.settings.reset('l2-vertical') + this.settings.reset('l2-horizontal') + this.settings.reset('size-l1') + this.settings.reset('size-l2') + this.settings.reset('opacity') + }) + prefsWidget.append(button_reset) + + this.settings.bind('text-l1', entry_line_1, 'text', Gio.SettingsBindFlags.DEFAULT) + this.settings.bind('text-l2', entry_line_2, 'text', Gio.SettingsBindFlags.DEFAULT) + this.settings.bind('l2-vertical', scale_line_2_vertical_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) + this.settings.bind('l2-horizontal', scale_line_2_horizontal_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) + this.settings.bind('size-l1', spinbutton_line_1_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) + this.settings.bind('size-l2', spinbutton_line_2_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) + this.settings.bind('opacity', scale_opacity.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT) + + group.add(prefsWidget); + } }