From d1c2eb361c5ac5526fb38e3a49c922b6616dc0d6 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 9 Nov 2018 17:29:06 +0800 Subject: [PATCH] first commit --- README.md | 1 + convenience.js | 93 ++++++++++++++++++ extension.js | 53 ++++++++++ metadata.json | 10 ++ prefs.js | 59 +++++++++++ schemas/gschemas.compiled | Bin 0 -> 392 bytes ...nome.shell.extensions.topicons.gschema.xml | 12 +++ stylesheet.css | 15 +++ 8 files changed, 243 insertions(+) create mode 100644 README.md create mode 100644 convenience.js create mode 100644 extension.js create mode 100644 metadata.json create mode 100644 prefs.js create mode 100644 schemas/gschemas.compiled create mode 100644 schemas/org.gnome.shell.extensions.topicons.gschema.xml create mode 100644 stylesheet.css diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee9ea67 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Activate Gnome diff --git a/convenience.js b/convenience.js new file mode 100644 index 0000000..bbc8608 --- /dev/null +++ b/convenience.js @@ -0,0 +1,93 @@ +/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (c) 2011-2012, Giovanni Campagna + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the GNOME nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +const Gettext = imports.gettext; +const Gio = imports.gi.Gio; + +const Config = imports.misc.config; +const ExtensionUtils = imports.misc.extensionUtils; + +/** + * initTranslations: + * @domain: (optional): the gettext domain to use + * + * Initialize Gettext to load translations from extensionsdir/locale. + * If @domain is not provided, it will be taken from metadata['gettext-domain'] + */ +function initTranslations(domain) { + let extension = ExtensionUtils.getCurrentExtension(); + + domain = domain || extension.metadata['gettext-domain']; + + // check if this extension was built with "make zip-file", and thus + // has the locale files in a subfolder + // otherwise assume that extension has been installed in the + // same prefix as gnome-shell + let localeDir = extension.dir.get_child('locale'); + if (localeDir.query_exists(null)) + Gettext.bindtextdomain(domain, localeDir.get_path()); + else + Gettext.bindtextdomain(domain, Config.LOCALEDIR); +} + +/** + * getSettings: + * @schema: (optional): the GSettings schema id + * + * Builds and return a GSettings schema for @schema, using schema files + * in extensionsdir/schemas. If @schema is not provided, it is taken from + * metadata['settings-schema']. + */ +function getSettings(schema) { + let extension = ExtensionUtils.getCurrentExtension(); + + schema = schema || extension.metadata['settings-schema']; + + const GioSSS = Gio.SettingsSchemaSource; + + // check if this extension was built with "make zip-file", and thus + // has the schema files in a subfolder + // otherwise assume that extension has been installed in the + // same prefix as gnome-shell (and therefore schemas are available + // in the standard folders) + let schemaDir = extension.dir.get_child('schemas'); + let schemaSource; + if (schemaDir.query_exists(null)) + schemaSource = GioSSS.new_from_directory(schemaDir.get_path(), + GioSSS.get_default(), + false); + else + schemaSource = GioSSS.get_default(); + + let schemaObj = schemaSource.lookup(schema, true); + if (!schemaObj) + throw new Error('Schema ' + schema + ' could not be found for extension ' + + extension.metadata.uuid + '. Please check your installation.'); + + return new Gio.Settings({ settings_schema: schemaObj }); +} + diff --git a/extension.js b/extension.js new file mode 100644 index 0000000..f4faf12 --- /dev/null +++ b/extension.js @@ -0,0 +1,53 @@ +// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- +// Sample extension code, makes clicking on the panel show a message +const St = imports.gi.St; +const Mainloop = imports.mainloop; + +const Gettext = imports.gettext.domain('activate_gnome'); +const _ = Gettext.gettext; + +const Main = imports.ui.main; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); +const Convenience = Me.imports.convenience; + + +function _show() { + let settings = Convenience.getSettings(); + let text1 = settings.get_string('text-l1') || _("Activate Gnome"); + let text2 = settings.get_string('text-l2') || _("Go to Settings to activate Gnome."); + label_1 = new St.Label({ style_class: 'label-1', text: text1 }); + label_2 = new St.Label({ style_class: 'label-2', text: text2 }); + let monitor = Main.layoutManager.primaryMonitor; + var h = Math.floor(monitor.height / 20 * 19 - label_2.height); + var w = Math.floor (monitor.width / 15 * 14 - label_2.width); + global.stage.add_actor(label_2); + label_2.set_position(w, h); + global.stage.add_actor(label_1); + label_1.set_position(w, h - label_1.height); +} + +// Put your extension initialization code here +function init(metadata) { + log ('Example extension initalized'); + Convenience.initTranslations(); +} + +function refresh() { + // Don't know how to get rid of this + disable(); + _show(); +} + +function enable() { + log ('Example extension enabled'); + _show(); + Mainloop.timeout_add(3000, () => { refresh(); }); +} + +function disable() { + log ('Example extension disabled'); + label_1.destroy(); + label_2.destroy(); +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..dc6dd36 --- /dev/null +++ b/metadata.json @@ -0,0 +1,10 @@ +{ + "extension-id": "activate_gnome", + "uuid": "activate_gnome@jerryxiao", + "settings-schema": "org.gnome.shell.extensions.activate_gnome", + "gettext-domain": "activate_gnome", + "name": "Gnome is not activated", + "description": "Shows Activate Gnome watermark on your screen.", + "shell-version": [ "3.30" ], + "url": "https://github.com/Jerry981028/activate_gnome" +} diff --git a/prefs.js b/prefs.js new file mode 100644 index 0000000..6c8e362 --- /dev/null +++ b/prefs.js @@ -0,0 +1,59 @@ +// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- + +const GLib = imports.gi.GLib; +const GObject = imports.gi.GObject; +const Gio = imports.gi.Gio; +const Gtk = imports.gi.Gtk; + +const Gettext = imports.gettext.domain('activate_gnome'); +const _ = Gettext.gettext; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); +const Convenience = Me.imports.convenience; + +function init() { + Convenience.initTranslations(); +} + +const ExamplePrefsWidget = GObject.registerClass( +class ExamplePrefsWidget extends Gtk.Grid { + _init(params) { + super._init(params); + this.margin = 12; + this.row_spacing = this.column_spacing = 6; + this.set_orientation(Gtk.Orientation.VERTICAL); + + this.add(new Gtk.Label({ label: '' + _("Line 1") + '', + use_markup: true, + halign: Gtk.Align.START })); + + let entryl1 = new Gtk.Entry({ hexpand: true, + margin_bottom: 12 }); + this.add(entryl1); + + this.add(new Gtk.Label({ label: '' + _("Line 2") + '', + use_markup: true, + halign: Gtk.Align.START })); + + let entryl2 = new Gtk.Entry({ hexpand: true, + margin_bottom: 12 }); + this.add(entryl2); + + this._settings = Convenience.getSettings(); + this._settings.bind('text-l1', entryl1, 'text', Gio.SettingsBindFlags.DEFAULT); + this._settings.bind('text-l2', entryl2, 'text', Gio.SettingsBindFlags.DEFAULT); + + let primaryText = _("You can customize the words on your screen."); + + this.add(new Gtk.Label({ label: primaryText, + wrap: true, xalign: 0 })); + } +}); + +function buildPrefsWidget() { + let widget = new ExamplePrefsWidget(); + widget.show_all(); + + return widget; +} diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled new file mode 100644 index 0000000000000000000000000000000000000000..8a54ce6a300e21308765b78b112c737b30c2fbfa GIT binary patch literal 392 zcmY*UOG*SW6f8f3f;&MF-1Ks0VS?VkRl6A6_+b`;1PMJ2Z6cG$FdGM#a~4nGH9UfQ z_hY@J8!@D)%F9b$RsG-=tqX#Foswrok9UV6d2|A7xys!%_dK%x{qeKaHq{ecW21+i zyb%|TX+nJQCe3}<8NU)AQX4}u?pfNU6aSR&^$jrIFASZlT5)&0`r6Yv|2)7FhvYNj z^KE^kepHWGugEvVec!KI`)A}eG5A*vOz}?M5JFSu-36|CLshMYX(mm~tCP892%AmX m9K!yEu>V6?AeG-PIiZe~#Ol_Iw4q6=hwd`L + + + 'Activate Gnome' + Text to display on line No.1 + + + 'Go to Settings to activate Gnome.' + Text to display on line No.2 + + + diff --git a/stylesheet.css b/stylesheet.css new file mode 100644 index 0000000..26bbcfe --- /dev/null +++ b/stylesheet.css @@ -0,0 +1,15 @@ +/* Example stylesheet */ +.label-1 { + font-size: 36px; + font-weight: normal; + color: rgba(255, 255, 255, 0.3); + background-color: rgba(10, 10, 10, 0); + border-radius: 5px; +} +.label-2 { + font-size: 26px; + font-weight: normal; + color: rgba(255, 255, 255, 0.3); + background-color: rgba(10, 10, 10, 0); + border-radius: 5px; +}