Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gnome Shell 45 and 46 compatibility. #101

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions [email protected]/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// GPL v3
// Copyright 2018-2021 Romain F. T.

const { St, Clutter, GObject } = imports.gi;
const ModalDialog = imports.ui.modalDialog;
import St from 'gi://St';
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';

var CustomModalDialog = GObject.registerClass(
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';

export const CustomModalDialog = GObject.registerClass(
class CustomModalDialog extends ModalDialog.ModalDialog {
_init(textTitle, bodyWidget, textOkButton, callback) {
super._init();
Expand Down Expand Up @@ -35,4 +38,3 @@ class CustomModalDialog extends ModalDialog.ModalDialog {
}]);
}
});

128 changes: 62 additions & 66 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,51 @@
// GPL v3
// Copyright 2018-2021 Romain F. T.

const { St, Shell, GLib, Gio, Meta } = imports.gi;
const PanelMenu = imports.ui.panelMenu;
const Panel = imports.ui.panel;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
import St from 'gi://St';
import Shell from 'gi://Shell';
import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
import Meta from 'gi://Meta';

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';

const NoteBox = Me.imports.noteBox;
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';

const Gettext = imports.gettext.domain('notes-extension');
const _ = Gettext.gettext;
import * as NoteBox from './noteBox.js';

//------------------------------------------------------------------------------

const PATH = GLib.build_pathv('/', [GLib.get_user_data_dir(), '[email protected]']);
// which is usually ~/.local/share/[email protected]
export default class NotesExtension extends Extension {
enable() {
this._layerSetting = '';
this._settings = this.getSettings();
this._autoFocus = this._settings.get_boolean('auto-focus'); // XXX crado
this._dataPath = GLib.build_pathv('/', [GLib.get_user_data_dir(), '[email protected]']);
// which is usually ~/.local/share/[email protected]

var NOTES_MANAGER;
var SETTINGS;
var LAYER_SETTING;
var AUTO_FOCUS;

function init() {
ExtensionUtils.initTranslations();
try {
let a = Gio.file_new_for_path(PATH);
if (!a.query_exists(null)) {
a.make_directory(null);
try {
let a = Gio.file_new_for_path(this._dataPath);
if (!a.query_exists(null)) {
a.make_directory(null);
}
} catch (e) {
log(e.message);
}
} catch (e) {
log(e.message);
}
LAYER_SETTING = '';
}

function enable() {
SETTINGS = ExtensionUtils.getSettings();
AUTO_FOCUS = SETTINGS.get_boolean('auto-focus'); // XXX crado

NOTES_MANAGER = new NotesManager();
}
this._notesManager = new NotesManager(this);
}

function disable() {
NOTES_MANAGER.destroy();
disable() {
this._notesManager.destroy();

if (NOTES_MANAGER) {
NOTES_MANAGER = null;
}
if (this._notesManager) {
this._notesManager = null;
}

if (SETTINGS) {
SETTINGS = null;
if (this._settings) {
this._settings = null;
}
}
}

Expand All @@ -69,7 +61,12 @@ function disable() {
* new one.
*/
class NotesManager {
constructor() {
constructor(extension) {
this._extension = extension;
this._settings = extension.getSettings();
this._layerSetting = extension._layerSetting;
this._dataPath = extension._dataPath;

// Initialisation of the button in the top panel
this.panel_button = new PanelMenu.Button(0.0, _("Show notes"), false);
let icon = new St.Icon({
Expand Down Expand Up @@ -99,11 +96,11 @@ class NotesManager {
}

_bindKeyboardShortcut () {
this._useKeyboardShortcut = SETTINGS.get_boolean('use-shortcut');
this._useKeyboardShortcut = this._settings.get_boolean('use-shortcut');
if (this._useKeyboardShortcut) {
Main.wm.addKeybinding(
'notes-kb-shortcut',
SETTINGS,
this._settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.ALL,
this._onButtonPressed.bind(this)
Expand All @@ -115,7 +112,7 @@ class NotesManager {
let i = 0;
let ended = false;
while(!ended) {
let file2 = GLib.build_filenamev([PATH, i.toString() + '_state']);
let file2 = GLib.build_filenamev([this._dataPath, i.toString() + '_state']);
if (GLib.file_test(file2, GLib.FileTest.EXISTS)) {
this.createNote('', 16);
} else {
Expand All @@ -133,7 +130,7 @@ class NotesManager {
createNote (colorString, fontSize) {
let nextId = this._allNotes.length;
try {
this._allNotes.push(new NoteBox.NoteBox(nextId, colorString, fontSize));
this._allNotes.push(new NoteBox.NoteBox(nextId, colorString, fontSize, this._extension));
} catch (e) {
Main.notify(_("Notes extension error: failed to load a note"));
log('failed to create note n°' + nextId.toString());
Expand Down Expand Up @@ -187,7 +184,7 @@ class NotesManager {

_hideNotes () {
this._onlyHideNotes();
this._timeout_id = Mainloop.timeout_add(10, () => {
this._timeout_id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 10, () => {
this._timeout_id = null;
// saving to the disk is slightly delayed to give the illusion that
// the extension doesn't freeze the system
Expand All @@ -206,7 +203,7 @@ class NotesManager {
}

_deleteNoteFiles (id) {
let filePathBeginning = PATH + '/' + id.toString();
let filePathBeginning = this._dataPath + '/' + id.toString();
let textfile = Gio.file_new_for_path(filePathBeginning + '_text');
let statefile = Gio.file_new_for_path(filePathBeginning + '_state');
textfile.delete(null); // may not do anything
Expand All @@ -220,7 +217,7 @@ class NotesManager {
// log('_onButtonPressed');

let preventReshowing = false;
if(LAYER_SETTING === 'cycle-layers') {
if(this._layerSetting === 'cycle-layers') {
this._allNotes.forEach(function (n) {
n.removeFromCorrectLayer();
});
Expand Down Expand Up @@ -261,27 +258,27 @@ class NotesManager {
_connectAllSignals () {
this._settingsSignals = {};

this._settingsSignals['layout'] = SETTINGS.connect(
this._settingsSignals['layout'] = this._settings.connect(
'changed::layout-position',
this._updateLayerSetting.bind(this)
);
this._settingsSignals['bring-back'] = SETTINGS.connect(
this._settingsSignals['bring-back'] = this._settings.connect(
'changed::ugly-hack',
this._bringToPrimaryMonitorOnly.bind(this)
);
this._settingsSignals['hide-icon'] = SETTINGS.connect(
this._settingsSignals['hide-icon'] = this._settings.connect(
'changed::hide-icon',
this._updateIconVisibility.bind(this)
);
this._settingsSignals['kb-shortcut-1'] = SETTINGS.connect(
this._settingsSignals['kb-shortcut-1'] = this._settings.connect(
'changed::use-shortcut',
this._updateShortcut.bind(this)
);
this._settingsSignals['kb-shortcut-2'] = SETTINGS.connect(
this._settingsSignals['kb-shortcut-2'] = this._settings.connect(
'changed::notes-kb-shortcut',
this._updateShortcut.bind(this)
);
this._settingsSignals['auto-focus'] = SETTINGS.connect(
this._settingsSignals['auto-focus'] = this._settings.connect(
'changed::auto-focus',
this._updateFocusSetting.bind(this)
);
Expand All @@ -303,7 +300,7 @@ class NotesManager {
}

_updateIconVisibility () {
let now_visible = !SETTINGS.get_boolean('hide-icon');
let now_visible = !this._settings.get_boolean('hide-icon');
this.panel_button.visible = now_visible;
}

Expand All @@ -323,8 +320,8 @@ class NotesManager {
n.removeFromCorrectLayer();
});

LAYER_SETTING = SETTINGS.get_string('layout-position');
this._layerId = (LAYER_SETTING == 'on-background')
this._layerSetting = this._settings.get_string('layout-position');
this._layerId = (this._layerSetting == 'on-background')
? 'on-background'
: 'above-all'
;
Expand All @@ -341,12 +338,12 @@ class NotesManager {
//--------------------------------------------------------------------------

destroy() {
SETTINGS.disconnect(this._settingsSignals['layout']);
SETTINGS.disconnect(this._settingsSignals['bring-back']);
SETTINGS.disconnect(this._settingsSignals['hide-icon']);
SETTINGS.disconnect(this._settingsSignals['kb-shortcut-1']);
SETTINGS.disconnect(this._settingsSignals['kb-shortcut-2']);
SETTINGS.disconnect(this._settingsSignals['auto-focus']);
this._settings.disconnect(this._settingsSignals['layout']);
this._settings.disconnect(this._settingsSignals['bring-back']);
this._settings.disconnect(this._settingsSignals['hide-icon']);
this._settings.disconnect(this._settingsSignals['kb-shortcut-1']);
this._settings.disconnect(this._settingsSignals['kb-shortcut-2']);
this._settings.disconnect(this._settingsSignals['auto-focus']);

this._allNotes.forEach(function (n) {
n.onlySave(false);
Expand All @@ -360,11 +357,10 @@ class NotesManager {
this.panel_button.destroy();

if (this._timeout_id) {
Mainloop.source_remove(this._timeout_id);
GLib.source_remove(this._timeout_id);
this._timeout_id = null;
}
}
};

//------------------------------------------------------------------------------

56 changes: 24 additions & 32 deletions [email protected]/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
// GPL v3
// Copyright 2018-2021 Romain F. T.

const { Clutter, St } = imports.gi;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const ShellEntry = imports.ui.shellEntry;
const Signals = imports.signals;
const Util = imports.misc.util;
import Clutter from 'gi://Clutter';
import St from 'gi://St';

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Extension = Me.imports.extension;
import {gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';

const Gettext = imports.gettext.domain('notes-extension');
const _ = Gettext.gettext;
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as Signals from 'resource:///org/gnome/shell/misc/signals.js';

const PRESET_COLORS = {
'red': [200, 0, 0],
Expand All @@ -31,8 +26,13 @@ const PRESET_COLORS = {

//------------------------------------------------------------------------------

class NoteOptionsMenu {
class NoteOptionsMenu extends Signals.EventEmitter {
constructor (source) {
super ();

this._extension = source._extension;
console.log(this._extension.path);

this.super_menu = new PopupMenu.PopupMenu(source.actor, 0.2, St.Side.LEFT);

// We want to keep the item hovered while the menu is up
Expand Down Expand Up @@ -102,7 +102,7 @@ class NoteOptionsMenu {

this._appendSeparator(); //---------------------------------------------

this.super_menu.addAction(_("Settings"), this._onSettings);
this.super_menu.addAction(_("Settings"), this._onSettings.bind(this));
}

_buildCustomColorMenu (colorSubmenu) {
Expand Down Expand Up @@ -187,8 +187,8 @@ class NoteOptionsMenu {
let btn = new St.Button({
style_class: 'notesCircleButton',
style: 'background-color: rgb(' + rgb[0] + ','
+ rgb[1] + ','
+ rgb[2] + ');',
+ rgb[1] + ','
+ rgb[2] + ');',
x_expand: true,
x_align: Clutter.ActorAlign.CENTER,
});
Expand All @@ -212,12 +212,9 @@ class NoteOptionsMenu {
}

_onSettings () {
if (typeof ExtensionUtils.openPrefs === 'function') {
ExtensionUtils.openPrefs();
} else {
Util.spawn(['gnome-shell-extension-prefs', '[email protected]']);
}
Extension.NOTES_MANAGER._hideNotes();
console.log(this._extension.path);
this._extension.openPreferences();
this._extension.notesManager._hideNotes();
}

_onEditTitle () {
Expand All @@ -242,12 +239,15 @@ class NoteOptionsMenu {
this._source._note.changeFontSize(-1);
}
};
Signals.addSignalMethods(NoteOptionsMenu.prototype);

//------------------------------------------------------------------------------

var NoteRoundButton = class NoteRoundButton {
export const NoteRoundButton = class NoteRoundButton extends Signals.EventEmitter {
constructor (note, icon, accessibleName) {
super ();

this._extension = note._extension;

this._note = note;
this.actor = new St.Button({
child: new St.Icon({
Expand All @@ -272,13 +272,7 @@ var NoteRoundButton = class NoteRoundButton {

addMenu () {
this._menu = null;
try {
// before 3.33, the constructor uses this.actor
this._menuManager = new PopupMenu.PopupMenuManager(this);
} catch (e) {
// after 3.33, the constructor uses directly the parameter
this._menuManager = new PopupMenu.PopupMenuManager(this.actor);
}
this._menuManager = new PopupMenu.PopupMenuManager(this.actor);
this.actor.connect('button-press-event', this.popupMenu.bind(this));
}

Expand All @@ -299,7 +293,5 @@ var NoteRoundButton = class NoteRoundButton {
return false;
}
};
Signals.addSignalMethods(NoteRoundButton.prototype);

//------------------------------------------------------------------------------

Loading