diff --git a/Makefile b/Makefile index 7399e80..12f4f40 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ dist: compile pnpm dist:format gnome-extensions pack --force --out-dir dist build \ --extra-source=../metadata.json \ - --extra-source=ui \ + --extra-source=ui --extra-source=lib \ $(addprefix --extra-source=../,$(DIST-EXTRA-SRC)) \ $(addprefix --schema=../,$(wildcard schemas/*.gschema.xml)) diff --git a/src/lib/prefs/about_page.ts b/src/lib/prefs/about_page.ts new file mode 100644 index 0000000..5137c16 --- /dev/null +++ b/src/lib/prefs/about_page.ts @@ -0,0 +1,85 @@ +// Copyright Sebastian Wiesner +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// +// Alternatively, the contents of this file may be used under the terms +// of the GNU General Public License Version 2 or later, as described below: +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import GObject from "gi://GObject"; +import Gtk from "gi://Gtk"; +import Adw from "gi://Adw"; + +import type { ExtensionMetadata } from "@girs/gnome-shell/extensions/extension"; + +import { getTemplate } from "./template.js"; + +const LICENSE = `Copyright Sebastian Wiesner + +This programm is subject to the terms of the Mozilla Public +License, v. 2.0. If a copy of the MPL was not distributed with this +file, You can obtain one at https://mozilla.org/MPL/2.0/. + +Alternatively, this program may be used under the terms +of the GNU General Public License Version 2 or later, as described below: + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details.`; + +interface AboutPageChildren { + _extensionName: Gtk.Label; + _extensionDescription: Gtk.Label; + _linkGithub: Gtk.LinkButton; + _linkIssues: Gtk.LinkButton; + _extensionLicense: Gtk.TextView; +} + +class TypescriptTemplateAboutPage extends Adw.PreferencesPage { + constructor(metadata: ExtensionMetadata) { + super(); + const children = this as unknown as AboutPageChildren; + children._extensionName.set_text(metadata.name); + children._extensionDescription.set_text(metadata.description); + if (metadata.url) { + children._linkGithub.set_uri(metadata.url); + children._linkIssues.set_uri(`${metadata.url}/issues`); + } else { + children._linkGithub.visible = false; + children._linkIssues.visible = false; + } + children._extensionLicense.buffer.set_text(LICENSE, -1); + } +} + +export default GObject.registerClass( + { + GTypeName: "TypescriptTemplateAboutPage", + Template: getTemplate("AboutPage"), + InternalChildren: [ + "extensionName", + "extensionDescription", + "linkGithub", + "linkIssues", + "extensionLicense", + ], + }, + TypescriptTemplateAboutPage, +); diff --git a/src/lib/prefs/general_page.ts b/src/lib/prefs/general_page.ts new file mode 100644 index 0000000..dea4d7b --- /dev/null +++ b/src/lib/prefs/general_page.ts @@ -0,0 +1,52 @@ +// Copyright Sebastian Wiesner +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// +// Alternatively, the contents of this file may be used under the terms +// of the GNU General Public License Version 2 or later, as described below: +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import GObject from "gi://GObject"; +import Gio from "gi://Gio"; +import Adw from "gi://Adw"; + +import { getTemplate } from "./template.js"; + +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +interface TypescriptTemplateGeneralPage { + _sayHello: Adw.SwitchRow; +} + +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging +class TypescriptTemplateGeneralPage extends Adw.PreferencesPage { + constructor(settings: Gio.Settings) { + super(); + + settings.bind( + "say-hello", + this._sayHello, + "active", + Gio.SettingsBindFlags.DEFAULT, + ); + } +} + +export default GObject.registerClass( + { + GTypeName: "TypescriptTemplateGeneralPage", + Template: getTemplate("GeneralPage"), + InternalChildren: ["sayHello"], + }, + TypescriptTemplateGeneralPage, +); diff --git a/src/lib/prefs/template.ts b/src/lib/prefs/template.ts new file mode 100644 index 0000000..efe1dc9 --- /dev/null +++ b/src/lib/prefs/template.ts @@ -0,0 +1,27 @@ +// Copyright Sebastian Wiesner +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// +// Alternatively, the contents of this file may be used under the terms +// of the GNU General Public License Version 2 or later, as described below: +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import GLib from "gi://GLib"; + +export const getTemplate = (name: string): string => + GLib.uri_resolve_relative( + import.meta.url, + `ui/${name}.ui`, + GLib.UriFlags.NONE, + ); diff --git a/src/prefs.ts b/src/prefs.ts index 66be001..677301e 100644 --- a/src/prefs.ts +++ b/src/prefs.ts @@ -17,104 +17,13 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -import GObject from "gi://GObject"; -import GLib from "gi://GLib"; import Gio from "gi://Gio"; -import Gtk from "gi://Gtk"; import Adw from "gi://Adw"; import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js"; -import type { ExtensionMetadata } from "@girs/gnome-shell/extensions/extension"; - -const LICENSE = `Copyright Sebastian Wiesner - -This programm is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -file, You can obtain one at https://mozilla.org/MPL/2.0/. - -Alternatively, this program may be used under the terms -of the GNU General Public License Version 2 or later, as described below: - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details.`; - -const getTemplate = (name: string): string => - GLib.uri_resolve_relative( - import.meta.url, - `ui/${name}.ui`, - GLib.UriFlags.NONE, - ); - -interface GeneralPageChildren { - _sayHello: Adw.SwitchRow; -} - -const GeneralPage = GObject.registerClass( - { - GTypeName: "TypescriptTemplateGeneralPage", - Template: getTemplate("GeneralPage"), - InternalChildren: ["sayHello"], - }, - class TypescriptTemplateGeneralPage extends Adw.PreferencesPage { - constructor(settings: Gio.Settings) { - super(); - - const children = this as unknown as GeneralPageChildren; - settings.bind( - "say-hello", - children._sayHello, - "active", - Gio.SettingsBindFlags.DEFAULT, - ); - } - }, -); - -interface AboutPageChildren { - _extensionName: Gtk.Label; - _extensionDescription: Gtk.Label; - _linkGithub: Gtk.LinkButton; - _linkIssues: Gtk.LinkButton; - _extensionLicense: Gtk.TextView; -} - -const AboutPage = GObject.registerClass( - { - GTypeName: "TypescriptTemplateAboutPage", - Template: getTemplate("AboutPage"), - InternalChildren: [ - "extensionName", - "extensionDescription", - "linkGithub", - "linkIssues", - "extensionLicense", - ], - }, - class TypescriptTemplateAboutPage extends Adw.PreferencesPage { - constructor(metadata: ExtensionMetadata) { - super(); - const children = this as unknown as AboutPageChildren; - children._extensionName.set_text(metadata.name); - children._extensionDescription.set_text(metadata.description); - if (metadata.url) { - children._linkGithub.set_uri(metadata.url); - children._linkIssues.set_uri(`${metadata.url}/issues`); - } else { - children._linkGithub.visible = false; - children._linkIssues.visible = false; - } - children._extensionLicense.buffer.set_text(LICENSE, -1); - } - }, -); +import AboutPage from "./lib/prefs/about_page.js"; +import GeneralPage from "./lib/prefs/general_page.js"; export default class HelloWorldPreferences extends ExtensionPreferences { override fillPreferencesWindow(