update
This commit is contained in:
@@ -1,74 +1,67 @@
|
||||
import Meta from 'gi://Meta';
|
||||
import St from 'gi://St';
|
||||
import Gio from 'gi://Gio';
|
||||
import GLib from 'gi://GLib';
|
||||
|
||||
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
|
||||
import {CalendarPanel} from './calendar.js';
|
||||
import {NotesPanel} from './notes.js';
|
||||
import {Store} from './store.js';
|
||||
import {Sync} from './sync.js';
|
||||
import {TodoPanel} from './todos.js';
|
||||
|
||||
const MARGIN = 24;
|
||||
|
||||
// GNOME lädt Extension-Code nur einmal pro Sitzung. Deshalb ist diese Datei nur ein Lader:
|
||||
// Beim Einschalten kopiert er die Module in einen frischen Ordner und importiert sie von dort.
|
||||
// Neuer Ordner heißt neue Adresse, also lädt GJS wirklich den aktuellen Code. Nach einer
|
||||
// Änderung reicht so make update (kopiert, schaltet aus und ein), ohne Ab- und Anmelden.
|
||||
// Nur diese Datei selbst wirkt erst nach dem nächsten Anmelden.
|
||||
export default class DesktopExtension extends Extension {
|
||||
_generation = 0;
|
||||
|
||||
enable() {
|
||||
this._store = new Store();
|
||||
|
||||
// Nur die Panels sind reaktiv. Der Rest lässt Klicks zum Desktop durch.
|
||||
this._root = new St.BoxLayout({style_class: 'desktop-root', reactive: false});
|
||||
this._notes = new NotesPanel(this._store);
|
||||
this._root.add_child(this._notes);
|
||||
// Rechte Spalte füllt den Rest, der Abstand dazwischen entspricht dem Außenrand.
|
||||
const right = new St.BoxLayout({vertical: true, style_class: 'desktop-right', reactive: false, x_expand: true});
|
||||
right.add_child(new CalendarPanel(this._store));
|
||||
right.add_child(new TodoPanel(this._store));
|
||||
this._root.add_child(right);
|
||||
|
||||
global.window_group.add_child(this._root);
|
||||
this._restackId = global.display.connect('restacked', () => this._restack());
|
||||
this._mapId = global.window_manager.connect('map', () => this._restack());
|
||||
this._workareaId = global.display.connect('workareas-changed', () => this._layout());
|
||||
this._layout();
|
||||
this._restack();
|
||||
|
||||
this._sync = new Sync(this._store);
|
||||
this._sync.start();
|
||||
const generation = ++this._generation;
|
||||
const dir = copyModules(this.dir);
|
||||
import(`${dir.get_uri()}/app.js`)
|
||||
.then(app => {
|
||||
// Inzwischen aus- oder erneut eingeschaltet: dieser Stand ist überholt
|
||||
if (this._generation !== generation)
|
||||
return;
|
||||
this._app = app;
|
||||
app.enable(this);
|
||||
})
|
||||
.catch(e => console.error(`desktop@marha.de: Laden fehlgeschlagen: ${e.message}\n${e.stack}`));
|
||||
}
|
||||
|
||||
disable() {
|
||||
this._sync.stop();
|
||||
this._sync = null;
|
||||
global.display.disconnect(this._restackId);
|
||||
global.window_manager.disconnect(this._mapId);
|
||||
global.display.disconnect(this._workareaId);
|
||||
this._root.destroy();
|
||||
this._root = null;
|
||||
this._notes = null;
|
||||
this._store = null;
|
||||
}
|
||||
|
||||
// Füllt den Arbeitsbereich des Hauptmonitors (ohne Topbar und Dock). Notizen nehmen die halbe Bildschirmbreite.
|
||||
_layout() {
|
||||
const area = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
||||
this._root.set_position(area.x + MARGIN, area.y + MARGIN);
|
||||
this._root.set_size(area.width - 2 * MARGIN, area.height - 2 * MARGIN);
|
||||
this._notes.set_width(Math.round(Main.layoutManager.primaryMonitor.width / 2));
|
||||
}
|
||||
|
||||
// Liegt direkt über Desktop-Fenstern (z.B. Desktop Icons), sonst direkt über dem Wallpaper.
|
||||
// Mutter sortiert die Fensterebene bei jedem Restack neu, daher hier nachziehen.
|
||||
_restack() {
|
||||
let below = Main.layoutManager._backgroundGroup;
|
||||
for (const actor of global.window_group.get_children()) {
|
||||
if (!(actor instanceof Meta.WindowActor))
|
||||
continue;
|
||||
const window = actor.meta_window;
|
||||
const isDing = window.customJS_ding || window.title?.startsWith('Desktop Icons');
|
||||
if (isDing || window.window_type === Meta.WindowType.DESKTOP)
|
||||
below = actor;
|
||||
}
|
||||
global.window_group.set_child_above_sibling(this._root, below);
|
||||
this._generation++;
|
||||
this._app?.disable(this);
|
||||
this._app = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Alle Module außer dieser Datei nach ~/.cache/desktop-app/live-<Zeit> kopieren. Ältere Kopien
|
||||
// sind schon geladen und werden gelöscht.
|
||||
function copyModules(source) {
|
||||
const base = Gio.File.new_for_path(GLib.build_filenamev([GLib.get_user_cache_dir(), 'desktop-app']));
|
||||
GLib.mkdir_with_parents(base.get_path(), 0o700);
|
||||
for (const name of listNames(base)) {
|
||||
if (name.startsWith('live-'))
|
||||
removeDir(base.get_child(name));
|
||||
}
|
||||
const dest = base.get_child(`live-${GLib.get_real_time()}`);
|
||||
dest.make_directory(null);
|
||||
for (const name of listNames(source)) {
|
||||
if (name.endsWith('.js') && name !== 'extension.js')
|
||||
source.get_child(name).copy(dest.get_child(name), Gio.FileCopyFlags.OVERWRITE, null, null);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
function listNames(dir) {
|
||||
const names = [];
|
||||
const children = dir.enumerate_children('standard::name', Gio.FileQueryInfoFlags.NONE, null);
|
||||
let info;
|
||||
while ((info = children.next_file(null)))
|
||||
names.push(info.get_name());
|
||||
children.close(null);
|
||||
return names;
|
||||
}
|
||||
|
||||
function removeDir(dir) {
|
||||
for (const name of listNames(dir))
|
||||
dir.get_child(name).delete(null);
|
||||
dir.delete(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user