* Add native video wallpaper support * Pause video wallpapers while a fullscreen app is focused * Sample one frame when a video background sets the bar text colour A video wallpaper made the transparent bar's colour sampling decode the entire file. ImageMagick's video delegate runs ffmpeg with no frame limit, so a twenty-second 1080p background took 11.3s of CPU where one frame takes 0.14s, and it did that on every theme change. The result was unusable anyway: a multi-frame input emits one value per frame, which the single-value match then rejected, so transparent bars silently fell back to the plain text colour on every video wallpaper. Selecting frame zero fixes the cost and the colour together, and fixes animated GIFs, which had the same bug. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Load wallpaper video lazily, and without an audio output Three costs the still-image path should never have paid. BackgroundMedia imported QtMultimedia at file scope and was instantiated on every output, so the module and its audio dependency closure mapped into every shell process whether or not a video was ever shown — measured at +2.72 MiB RSS. Moving the element into its own file behind a Loader that takes a URL defers the whole import: an inactive loader maps none of it, an active one maps all 25 libraries. An inline Component cannot defer that, because the type has to resolve when the file compiles. Qt's Video convenience type always builds an AudioOutput, and `muted` only aliases that sink's volume, so every monitor decoded an audio stream it would never play and opened an audio client for it. A bare MediaPlayer with no audio output spawns no QFFmpeg::AudioR, QAudioContext or PWDevMon thread, and plays files with no audio track just the same. The shared image also turned mipmapping on, which the desktop background never had. A full mip chain is about a third more texture memory — 10.6 MiB extra at 4K, per output — for a wallpaper drawn at its own size. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Stop wallpaper playback while the session is locked or screensaved Playback stopped only for a focused fullscreen window. Locking the session did not stop it, and the lock screen starts a player of its own, so an N-monitor desktop reached 2N decode pipelines the moment it locked — and stayed there, because a display blanked for idle stops being presented but does not stop Qt's FFmpeg engine, which drives its own clock. A laptop locked with the lid shut decoded video until the battery ran out. The lock and idle services already know both states, so the background service takes the shell reference the loader offers it and reads them. Looking a service up by id needs the registry to be reactive, or a background that loads before the lock service would bind to null and stay there. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Fan out video thumbnails narrower than single-threaded image jobs The generator fans out one job per core, which was bounded because VIPS_CONCURRENCY=1 made each of them single-threaded. ffmpegthumbnailer leaves FFmpeg's automatic decoder threading on, so a folder of uncached videos put a codec thread pool on every core at once. Queueing video work separately keeps the still-image path at full width and gives the video path a quarter of it. * Recognize a named video file as a theme preview The backgrounds fallback beside it already picks videos, so a theme shipping preview.mp4 was the one case that still went unseen. * Document video backgrounds in the manual The manual described backgrounds as images only. Worth saying plainly that a video wallpaper costs far more power than a still one and that each monitor decodes its own copy, since neither is visible from the picker. * Stop the lock screen's own playback once the displays go dark Pausing the desktop wallpaper on lock only moved the cost. The lock screen builds a player per monitor of its own, so locking an N-monitor session went from N decoders to N rather than to none — and the lock service blanks the displays five seconds later without touching them, which is where a lock spends nearly all of its time. A laptop locked and shut still decoded video into a dark panel. The service already owns both transitions, so it records whether the displays are dark and the lock view stops playback while they are. The manual said playback stops while the screen is locked, which was the same overstatement; it now says once a locked screen has gone dark. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Keep videos out of the lazy thumbnail path A lazy row stands in with the media file itself until its thumbnail exists, and the picker draws that with an Image — which shows a picture and shows nothing for a video, with no reload once the real thumbnail lands. So the first open after discovering an uncached video showed a blank tile. The same branch also spawns one generator per file immediately, before either queue is reached, and the theme switcher always asks for lazy thumbnails. That put the narrower video fan out on the one path that never used it: forty uncached previews meant forty ffmpegthumbnailer processes. Sending videos to the queue instead fixes the blank tile and puts them back under the cap. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Rebuild the theme preview cache after teaching it about video Preview discovery changed what it recognizes, but its cache keys on theme directory mtimes alone. A theme that already shipped a video preview would keep whatever the old rules cached until something happened to touch the directory. Bumping the version rebuilds it once. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Drop an activeAudioTrack setting that never took effect Qt's FFmpeg backend ignores setActiveTrack while no source is open, and the literal binding is not reapplied once the media loads and the tracks become known, so the line did nothing. What actually keeps the audio decoder and its client from ever being built is the absent audio output, which a file carrying an audio track confirms on its own: no QFFmpeg::AudioR, QAudioContext or PWDevMon thread appears without it. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Give up the blank state when a display comes back The lock screen stops its wallpaper while the displays are dark, but it was tracking the blanking it asked for rather than the panels themselves. Opening a docked lid turns the internal panel back on without going through runWake, and so does a resume, which left a visible lock wallpaper frozen on one frame until the next keypress. A frozen wallpaper someone is looking at is worse than the decoding it saves, so a screen change gives the state up. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Time bound the video thumbnail generator Routing videos through the queue means they are generated before the picker opens rather than behind it, which turned an unreadable or stalled file into a picker that never opens. ffmpegthumbnailer had no bound of its own and the drain waits for every job. A generator that gives up is already handled: the run reports failure, the partial file is removed, and the row drops out of the list. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Pause only the output a fullscreen window covers The fullscreen test was global, so a game on one monitor stopped the wallpaper on every other one — including the ones still in plain view. That is the failure the lock work was careful to avoid, and it made the manual's claim that playback stops when nothing can see it untrue for the commonest multi-monitor case. A lock or a screensaver does cover every output, so those stay a single decision; fullscreen is now matched against the focused monitor, the way the bar already routes by output. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Kill a video thumbnail generator that ignores the timeout Plain timeout sends TERM and then waits for a process that may never take it, which leaves the bound it was added for unenforced on exactly the stuck files it was meant to catch. Co-Authored-By: Codex XHigh <noreply@anthropic.com> * Pause video wallpapers in battery power-saver * Fix paused video wallpaper source priming * Skip snapshots for video background transitions (cherry picked from commit 6f759538bfa76c2da03634e98ebfc2ebf63ec68e) * Generate thumbnails for direct-scan videos (cherry picked from commit 10fcca018a865dca311fb6863e8c8b0057291223) * Remember a video the thumbnail converter rejected A permanently unreadable video cost ten seconds of generator time on every picker open before its row dropped, because nothing recorded the failure. Both the menu image generator and the direct picker scan now leave a marker beside the missing thumbnail, keyed like the thumbnail on the file's size and mtime, so a repaired file starts clean. A timeout is left to retry, as it may only have been a busy machine. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Follow the panels' real DPMS state under a locked video wallpaper The lock screen stopped video playback when it asked for the displays to blank, and resumed on input, but never checked what the panels did. A blank that failed left a lit panel on one frozen frame, and a resume that turned the same outputs back on played nothing until the next keypress. Quickshell exposes no DPMS signal, so while a video is the locked wallpaper the lock polls hyprctl and decides per surface from the answer. A wake or blank request drops the last answer so its optimistic state applies until the next poll confirms it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Pause a video wallpaper for the fullscreen window that covers it The fullscreen check read the globally active window and the focused monitor, so it only knew about the window that had focus. A fullscreen window left on one monitor while focus moved to another resumed the wallpaper decoding behind it, and with fullscreen windows on two outputs only the focused one paused. Each output's visible workspace reports whether a fullscreen window covers it, and Quickshell flips that on the compositor's fullscreen event, so each panel now decides from its own monitor's active workspace instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Reopen a video wallpaper a theme switch replaced behind its path Two themes that both ship backgrounds/wallpaper.mp4 leave the current background at the same path after a switch, so the displayed path never changed and the running player kept decoding the old file from its open descriptor. Stills go through the snapshot transition and survive this; a video switch is instant and did not. A forced switch onto the path already on show now bumps a reload counter, and BackgroundMedia rebuilds the video player for it. A cache-busting query is not an option there, since FFmpeg reads it as part of the filename. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Keep picker rows uncached while a rejected video is left out Skipping a video with a failure marker let the picker cache its rows without it, and cached rows are trusted on the directory's mtime alone. A file repaired in place never touches that, so the marker's fresh key was never consulted and the video stayed missing. The generator now hands the marker back to the row loop, which drops the row and leaves the rows uncached, so each open re-stats the file and a repaired one is converted again. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Hand each background loader only its own kind of file BackgroundMedia fed one URL to both the still loader and the video player. On a switch from image to video the Image was handed the video's URL in the moment before its loader unloaded, so Qt tried to decode the mp4 as a picture and logged an unsupported format on every such switch; the reverse handed the player a still to demux. The still URL is now empty whenever the path is a video and the video URL empty whenever it is a still, so a switch changes only the loader that stays. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Stop a video wallpaper before tearing its player down Switching from a video to a still destroys the BackgroundVideo item while its player is mid-read, which FFmpeg reports as a failed open in the shell journal on every such switch. Stopping the player on destruction lets the demuxer wind down first, and the switch is quiet. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Play a video wallpaper's sound track from the first monitor Video wallpapers were always silent: the player was built without an audio output, since a muted output still decodes the track and opens an audio client on every monitor. A video with music should be able to play it. The player now builds its AudioOutput only once the media reports a sound track, so a silent file still opens no audio client, and only the first screen's panel opts in, so a multi-monitor desktop does not layer copies of the track. The output is muted while a paused player primes its first frame, and the lock screen stays silent. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Keep a departing video player off the still's file The switch away from a video still logged a cancelled open, and stopping the player on destruction only hid it: stopping reports the media as loaded, which the loaded handler answered by playing again. The real cause was one evaluation pass. Both URLs derived from the `video` flag, which is itself bound to the path, and QML updates the two in no fixed order, so the video URL could evaluate against the stale flag and hand the player the still for a moment. Its destructor then cancelled that open. Each URL now tests the path directly, the source binding only applies while the path is a video and restores nothing when it stops, and the destruction stop goes away with the hazard it introduced. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Pin the audio wiring in the test and name the output in the manual The audio assertion passed with the BackgroundMedia forwarding binding removed, which would have left every wallpaper silent, and did not pin the silent default or the first-screen selection. It covers all three now. The manual said the sound track plays "from your first monitor", which reads as routing to that monitor's audio device. It is the first monitor's wallpaper that plays, through the default output. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Omabot <omabot@omarchy.org> Co-authored-by: Codex XHigh <noreply@anthropic.com> Co-authored-by: z8 <yam@kernelius.com> Co-authored-by: David Heinemeier Hansson <david@hey.com>
1059 lines
39 KiB
QML
1059 lines
39 KiB
QML
import QtQuick
|
|
import QtQml.Models
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
|
|
import qs.Commons
|
|
|
|
import "plugins/bar"
|
|
import "services"
|
|
|
|
ShellRoot {
|
|
id: shell
|
|
|
|
// Shared service instances. Plugins receive these via property injection
|
|
// rather than re-importing them as singletons — relative-path imports do
|
|
// not share singleton state, which silently leaves consumers with their
|
|
// own empty copies.
|
|
property PluginRegistry pluginRegistry: PluginRegistry { }
|
|
property BarWidgetRegistry barWidgetRegistry: BarWidgetRegistry { }
|
|
property AppLibrary appLibrary: AppLibrary { }
|
|
|
|
property string home: Quickshell.env("HOME")
|
|
|
|
// The omarchy-shell host is the long-running entry point. Plugins live in
|
|
// sibling directories under plugins/. OMARCHY_PATH is provided by the uwsm
|
|
// session environment and is the single source of truth for this checkout.
|
|
property string omarchyPath: Quickshell.env("OMARCHY_PATH")
|
|
readonly property string shellPath: omarchyPath + "/shell"
|
|
readonly property string firstPartyPluginsDir: shellPath + "/plugins"
|
|
readonly property string defaultsPath: omarchyPath + "/config/omarchy/shell.json"
|
|
readonly property string userConfigPath: home + "/.config/omarchy/shell.json"
|
|
|
|
// Bundled fallback so the shell can start even when the default shell.json is
|
|
// missing or unreadable. The bar config here mirrors the on-disk defaults
|
|
// closely enough to render a usable bar; not authoritative.
|
|
readonly property var builtinShellConfig: ({
|
|
version: 1,
|
|
idle: {
|
|
screensaver: 150,
|
|
lock: 300
|
|
},
|
|
bar: {
|
|
position: "top",
|
|
transparent: false,
|
|
centerAnchor: "omarchy.clock",
|
|
layout: {
|
|
left: [{ id: "omarchy.menu" }, { id: "omarchy.workspaces" }],
|
|
center: [{ id: "omarchy.clock", format: "dddd HH:mm" }],
|
|
right: [{ id: "omarchy.audio" }]
|
|
}
|
|
},
|
|
plugins: []
|
|
})
|
|
|
|
property var defaultsConfig: builtinShellConfig
|
|
property var shellConfig: builtinShellConfig
|
|
property bool pluginReloading: false
|
|
property bool pluginReloadPending: false
|
|
|
|
Timer {
|
|
id: localPluginReloadTimer
|
|
interval: 150
|
|
onTriggered: shell.reloadPlugins()
|
|
}
|
|
|
|
onShellConfigChanged: {
|
|
if (failedBarId !== "") failedBarId = ""
|
|
pluginRegistry.registryRevision++
|
|
pluginRegistry.pluginsChanged()
|
|
}
|
|
|
|
function applyShellConfig() {
|
|
// Decide which source is canonical: a valid user shell.json overrides
|
|
// defaults entirely; otherwise fall back to defaults. We do not deep-merge.
|
|
var defaults = Util.isPlainObject(defaultsConfig) ? defaultsConfig : builtinShellConfig
|
|
var user = null
|
|
var userText = userConfigFile.text() || ""
|
|
if (userText.trim()) {
|
|
try {
|
|
var parsed = JSON.parse(userText)
|
|
if (Util.isPlainObject(parsed) && parsed.version === 1) user = parsed
|
|
else if (Util.isPlainObject(parsed)) console.warn("shell.json missing version: 1, using defaults")
|
|
} catch (e) {
|
|
console.warn("shell.json parse failed, using defaults:", e)
|
|
}
|
|
}
|
|
shellConfig = user || defaults
|
|
}
|
|
|
|
function loadDefaults(raw) {
|
|
var text = String(raw || "").trim()
|
|
if (!text) {
|
|
defaultsConfig = builtinShellConfig
|
|
applyShellConfig()
|
|
return
|
|
}
|
|
try {
|
|
var parsed = JSON.parse(text)
|
|
if (Util.isPlainObject(parsed) && parsed.version === 1) defaultsConfig = parsed
|
|
else defaultsConfig = builtinShellConfig
|
|
} catch (e) {
|
|
console.warn("default shell.json parse failed, using builtin:", e)
|
|
defaultsConfig = builtinShellConfig
|
|
}
|
|
applyShellConfig()
|
|
}
|
|
|
|
function persistShellConfig(nextConfig) {
|
|
var payload = JSON.parse(JSON.stringify(nextConfig))
|
|
payload.version = 1
|
|
shellConfig = payload
|
|
userConfigFile.setText(JSON.stringify(payload, null, 2) + "\n")
|
|
}
|
|
|
|
readonly property var barConfig: shellConfig && Util.isPlainObject(shellConfig.bar) ? shellConfig.bar : builtinShellConfig.bar
|
|
onBarConfigChanged: if (bar && "barConfig" in bar) bar.barConfig = shell.barConfig
|
|
FileView {
|
|
id: defaultsFile
|
|
path: shell.defaultsPath
|
|
watchChanges: true
|
|
printErrors: false
|
|
onLoaded: shell.loadDefaults(text())
|
|
onLoadFailed: function(error) {
|
|
console.warn("default shell.json load failed: " + error + " path=" + shell.defaultsPath)
|
|
shell.loadDefaults("")
|
|
}
|
|
onFileChanged: reload()
|
|
}
|
|
|
|
FileView {
|
|
id: userConfigFile
|
|
path: shell.userConfigPath
|
|
watchChanges: true
|
|
atomicWrites: true
|
|
printErrors: false
|
|
onLoaded: shell.applyShellConfig()
|
|
onLoadFailed: function(error) { shell.applyShellConfig() }
|
|
onFileChanged: reload()
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
console.log("omarchy-shell paths",
|
|
"omarchyPath=" + shell.omarchyPath,
|
|
"shellDir=" + Quickshell.shellDir,
|
|
"firstPartyPluginsDir=" + shell.firstPartyPluginsDir,
|
|
"defaultsPath=" + shell.defaultsPath,
|
|
"userConfigPath=" + shell.userConfigPath)
|
|
pluginRegistry.firstPartyDir = shell.firstPartyPluginsDir
|
|
pluginRegistry.shellConfigProvider = function() { return shell.shellConfig }
|
|
pluginRegistry.shellConfigMutator = function(mutate) { shell.mutateShellConfig(mutate) }
|
|
// PluginRegistry.ensureUserDir() runs in its own Component.onCompleted and
|
|
// chains rescan() once the directory exists. We also kick a scan here in
|
|
// case the user dir already existed at startup.
|
|
pluginRegistry.rescan()
|
|
shell._syncServices()
|
|
}
|
|
|
|
function mutateShellConfig(mutator) {
|
|
var copy = JSON.parse(JSON.stringify(shellConfig || builtinShellConfig))
|
|
mutator(copy)
|
|
persistShellConfig(copy)
|
|
}
|
|
|
|
// Exposed as a property so child plugins (notifications, future panels)
|
|
// can read barSize/barHidden/position to anchor relative to the active bar.
|
|
readonly property string defaultBarId: "omarchy.bar"
|
|
readonly property string selectedBarId: {
|
|
var config = shell.barConfig
|
|
if (Util.isPlainObject(config)) {
|
|
var configured = Util.canonicalWidgetId(String(config.id || ""))
|
|
if (configured) return configured
|
|
}
|
|
return shell.defaultBarId
|
|
}
|
|
property string failedBarId: ""
|
|
readonly property bool selectedBarAvailable: {
|
|
var revision = shell.pluginRegistry.registryRevision
|
|
return shell.barOptionAvailable(shell.selectedBarId)
|
|
}
|
|
readonly property string activeBarId: selectedBarId !== failedBarId && selectedBarAvailable ? selectedBarId : defaultBarId
|
|
readonly property var activeBarManifest: {
|
|
var revision = shell.pluginRegistry.registryRevision
|
|
return shell.barManifestFor(shell.activeBarId)
|
|
}
|
|
readonly property string activeBarSourceUrl: activeBarId === defaultBarId ? "" : shell.pluginRegistry.entryPointUrl(activeBarManifest, "bar")
|
|
property var bar: null
|
|
|
|
onSelectedBarIdChanged: if (failedBarId !== "") failedBarId = ""
|
|
|
|
function barManifestFor(pluginId) {
|
|
var plugins = shell.pluginRegistry ? shell.pluginRegistry.installedPlugins : null
|
|
return plugins ? plugins[String(pluginId || "")] || null : null
|
|
}
|
|
|
|
function isBarOptionManifest(manifest) {
|
|
return manifest
|
|
&& Array.isArray(manifest.kinds)
|
|
&& manifest.kinds.indexOf("bar") !== -1
|
|
&& manifest.entryPoints
|
|
&& manifest.entryPoints.bar
|
|
}
|
|
|
|
function barOptionAvailable(pluginId) {
|
|
var id = String(pluginId || "")
|
|
if (id === "" || id === shell.defaultBarId) return true
|
|
var manifest = shell.barManifestFor(id)
|
|
return shell.isBarOptionManifest(manifest) && shell.pluginRegistry.entryPointUrl(manifest, "bar") !== ""
|
|
}
|
|
|
|
function isActiveBarOption(pluginId) {
|
|
return String(pluginId || "") === shell.activeBarId
|
|
}
|
|
|
|
function configureBar(target, manifest) {
|
|
if (!target) return
|
|
if ("omarchyPath" in target) target.omarchyPath = shell.omarchyPath
|
|
if ("shell" in target) target.shell = shell
|
|
if ("manifest" in target) target.manifest = manifest
|
|
if ("barWidgetRegistry" in target) target.barWidgetRegistry = shell.barWidgetRegistry
|
|
if ("pluginRegistry" in target) target.pluginRegistry = shell.pluginRegistry
|
|
if ("barConfig" in target) target.barConfig = shell.barConfig
|
|
shell.bar = target
|
|
}
|
|
|
|
Component {
|
|
id: defaultBarComponent
|
|
|
|
Bar {
|
|
omarchyPath: shell.omarchyPath
|
|
barWidgetRegistry: shell.barWidgetRegistry
|
|
barConfig: shell.barConfig
|
|
shell: shell
|
|
manifest: shell.barManifestFor(shell.defaultBarId)
|
|
}
|
|
}
|
|
|
|
Loader {
|
|
id: defaultBarLoader
|
|
|
|
active: shell.activeBarId === shell.defaultBarId
|
|
sourceComponent: defaultBarComponent
|
|
onLoaded: shell.configureBar(item, shell.barManifestFor(shell.defaultBarId))
|
|
onActiveChanged: if (!active && shell.activeBarId !== shell.defaultBarId) shell.bar = null
|
|
}
|
|
|
|
Loader {
|
|
id: pluginBarLoader
|
|
|
|
active: !shell.pluginReloading && shell.activeBarId !== shell.defaultBarId && shell.activeBarSourceUrl !== ""
|
|
source: shell.activeBarId !== shell.defaultBarId ? shell.activeBarSourceUrl : ""
|
|
asynchronous: true
|
|
onLoaded: shell.configureBar(item, shell.activeBarManifest)
|
|
onActiveChanged: if (!active) shell.bar = null
|
|
onStatusChanged: {
|
|
if (status === Loader.Error) {
|
|
var detail = errorString && errorString() ? errorString() : ""
|
|
console.warn("bar option " + shell.activeBarId + " failed to load, falling back to " + shell.defaultBarId + ":", detail)
|
|
shell.failedBarId = shell.activeBarId
|
|
}
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------- services
|
|
//
|
|
// Generic loader for any enabled plugin that declares kind "service".
|
|
// First-party infrastructure services are implicitly enabled by the registry;
|
|
// third-party services are enabled by adding the plugin id to shell.json.
|
|
Item {
|
|
id: serviceHost
|
|
visible: false
|
|
}
|
|
|
|
property var _services: ({})
|
|
|
|
// Reassigned as each service registers, so a binding that reads this before
|
|
// looking a service up by id re-evaluates once that service exists.
|
|
readonly property var services: _services
|
|
|
|
function serviceFor(pluginId) {
|
|
return _services[String(pluginId)] || null
|
|
}
|
|
|
|
function firstPartyServiceFor(pluginId) {
|
|
return serviceFor(pluginId)
|
|
}
|
|
|
|
function ensureService(pluginId) {
|
|
var key = String(pluginId)
|
|
if (_services[key]) return _services[key]
|
|
var manifest = pluginRegistry && pluginRegistry.installedPlugins
|
|
? pluginRegistry.installedPlugins[key] : null
|
|
if (!manifest) return null
|
|
if (!Array.isArray(manifest.kinds) || manifest.kinds.indexOf("service") === -1) return null
|
|
if (!manifest.entryPoints || !manifest.entryPoints.service) return null
|
|
var url = pluginRegistry.entryPointUrl(manifest, "service")
|
|
if (!url) return null
|
|
|
|
var comp = Qt.createComponent(url, Component.PreferSynchronous)
|
|
function finalize() {
|
|
if (comp.status !== Component.Ready) {
|
|
console.warn("service plugin load failed for " + key + ": " + comp.errorString())
|
|
return
|
|
}
|
|
var inst = comp.createObject(serviceHost)
|
|
if (!inst) {
|
|
console.warn("service plugin createObject returned null for", key)
|
|
return
|
|
}
|
|
if ("omarchyPath" in inst) inst.omarchyPath = shell.omarchyPath
|
|
if ("shell" in inst) inst.shell = shell
|
|
if ("manifest" in inst) inst.manifest = manifest
|
|
if ("barWidgetRegistry" in inst) inst.barWidgetRegistry = shell.barWidgetRegistry
|
|
if ("pluginRegistry" in inst) inst.pluginRegistry = shell.pluginRegistry
|
|
var snext = ({})
|
|
for (var sk in _services) snext[sk] = _services[sk]
|
|
snext[key] = inst
|
|
_services = snext
|
|
}
|
|
if (comp.status === Component.Loading) {
|
|
comp.statusChanged.connect(finalize)
|
|
return null
|
|
}
|
|
finalize()
|
|
return _services[key] || null
|
|
}
|
|
|
|
function _syncServices() {
|
|
if (!pluginRegistry || !pluginRegistry.installedPlugins) return
|
|
var plugins = pluginRegistry.installedPlugins
|
|
for (var id in plugins) {
|
|
var m = plugins[id]
|
|
if (!m) continue
|
|
if (!Array.isArray(m.kinds) || m.kinds.indexOf("service") === -1) continue
|
|
if (!m.entryPoints || !m.entryPoints.service) continue
|
|
if (!pluginRegistry.isEnabled(id)) continue
|
|
if (_services[id]) {
|
|
// A kept instance outlives the rescan; hand it the fresh manifest.
|
|
var kept = _services[id]
|
|
if (kept && "manifest" in kept) kept.manifest = m
|
|
continue
|
|
}
|
|
ensureService(id)
|
|
}
|
|
// Drop services for plugins that have been disabled or removed, or that
|
|
// no longer declare a service entry point.
|
|
for (var existingId in _services) {
|
|
var stillThere = plugins[existingId]
|
|
var stillService = stillThere && Array.isArray(stillThere.kinds)
|
|
&& stillThere.kinds.indexOf("service") !== -1
|
|
&& stillThere.entryPoints && stillThere.entryPoints.service
|
|
var stillEnabled = stillThere && pluginRegistry.isEnabled(existingId)
|
|
if (stillService && stillEnabled) continue
|
|
var inst = _services[existingId]
|
|
if (inst && typeof inst.destroy === "function") inst.destroy()
|
|
var next = ({})
|
|
for (var k in _services) if (k !== existingId) next[k] = _services[k]
|
|
_services = next
|
|
}
|
|
}
|
|
|
|
function serviceKeepLoaded(pluginId) {
|
|
var plugins = pluginRegistry && pluginRegistry.installedPlugins
|
|
var manifest = plugins ? plugins[pluginId] : null
|
|
return !!(manifest && manifest.keepLoaded === true)
|
|
}
|
|
|
|
// keepLoaded services (lock, idle, polkit) must survive plugin hot-reload.
|
|
// Destroying omarchy.lock drops the ext-session-lock client while Hyprland
|
|
// still holds the lock, which surfaces the crashed-lockscreen fallback.
|
|
function unloadPluginServices() {
|
|
var next = ({})
|
|
for (var existingId in _services) {
|
|
if (serviceKeepLoaded(existingId)) {
|
|
next[existingId] = _services[existingId]
|
|
continue
|
|
}
|
|
var inst = _services[existingId]
|
|
if (inst && typeof inst.destroy === "function") inst.destroy()
|
|
}
|
|
_services = next
|
|
}
|
|
|
|
Connections {
|
|
target: shell.pluginRegistry
|
|
function onPluginsChanged() { if (!shell.pluginReloading) shell._syncServices() }
|
|
}
|
|
|
|
// Writes inline settings to a bar layout entry or top-level plugin entry in
|
|
// shell.json. moduleName is the entry id; settings is the merged plugin
|
|
// state. Returns true if anything actually changed. Compute the proposed
|
|
// new shellConfig in a local clone, and only persist if anything actually
|
|
// changed so reactive bindings do not dirty shell.json unnecessarily.
|
|
function updateEntryInline(moduleName, settings) {
|
|
var stripped = Util.canonicalWidgetId(moduleName)
|
|
var copy = JSON.parse(JSON.stringify(shellConfig || builtinShellConfig))
|
|
if (!Util.isPlainObject(copy.bar)) copy.bar = { layout: { left: [], center: [], right: [] } }
|
|
if (!Util.isPlainObject(copy.bar.layout)) copy.bar.layout = { left: [], center: [], right: [] }
|
|
if (!Array.isArray(copy.plugins)) copy.plugins = []
|
|
|
|
var sections = ["left", "center", "right"]
|
|
var foundInLayout = false
|
|
var dirty = false
|
|
for (var s = 0; s < sections.length; s++) {
|
|
var arr = copy.bar.layout[sections[s]] || []
|
|
for (var i = 0; i < arr.length; i++) {
|
|
if (arr[i] && Util.canonicalWidgetId(arr[i].id) === stripped) {
|
|
var next = { id: stripped }
|
|
for (var k in settings) if (k !== "id") next[k] = settings[k]
|
|
if (JSON.stringify(arr[i]) !== JSON.stringify(next)) {
|
|
arr[i] = next
|
|
dirty = true
|
|
}
|
|
foundInLayout = true
|
|
}
|
|
}
|
|
}
|
|
if (!foundInLayout) {
|
|
for (var j = 0; j < copy.plugins.length; j++) {
|
|
if (copy.plugins[j] && copy.plugins[j].id === stripped) {
|
|
var pnext = { id: stripped }
|
|
for (var pk in settings) if (pk !== "id") pnext[pk] = settings[pk]
|
|
if (JSON.stringify(copy.plugins[j]) !== JSON.stringify(pnext)) {
|
|
copy.plugins[j] = pnext
|
|
dirty = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!dirty) return false
|
|
persistShellConfig(copy)
|
|
return true
|
|
}
|
|
|
|
// ---------------------------------------------------------- on-demand panels
|
|
|
|
// openPanelIds is a plain object treated as a set. A plugin id maps to
|
|
// `true` while the panel is summoned; deleting the key (well, building a new
|
|
// object without it) hides it. Reassigning the whole object is required for
|
|
// QML to notice the change.
|
|
property var openPanelIds: ({})
|
|
|
|
// Pending payloads to deliver to a plugin's open() once its loader resolves.
|
|
// Keyed by plugin id; the value is an array so two summon() calls before
|
|
// the Loader resolves both reach the plugin in arrival order rather than
|
|
// the second clobbering the first.
|
|
property var pendingPayloads: ({})
|
|
|
|
// Bar-widget panels (audio, bluetooth, network, power, monitor, etc.)
|
|
// are mounted inside the bar, not via the panel loader below. Route
|
|
// summon/hide/toggle to the live bar instance so panel hotkeys survive
|
|
// plugin/bar reloads: the bar re-creates the widget, while a fixed IPC
|
|
// target only ever routes to one of the per-monitor instances.
|
|
function isBarWidgetPanelPlugin(pluginId) {
|
|
var plugins = shell.pluginRegistry.installedPlugins
|
|
var m = plugins[String(pluginId || "")]
|
|
if (!m || !Array.isArray(m.kinds)) return false
|
|
if (m.kinds.indexOf("bar-widget") === -1) return false
|
|
// Plugins that are also panel/overlay/menu kinds are owned by the
|
|
// panel loader (e.g. omarchy.menu); let that path handle them.
|
|
var loaderKinds = ["panel", "overlay", "menu"]
|
|
for (var i = 0; i < loaderKinds.length; i++) {
|
|
if (m.kinds.indexOf(loaderKinds[i]) !== -1) return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
function summon(pluginId, payloadJson) {
|
|
var id = shell.pluginRegistry.resolveEnabledId(pluginId)
|
|
if (!id) return false
|
|
var plugins = shell.pluginRegistry.installedPlugins
|
|
if (!plugins[id]) {
|
|
console.warn("summon: unknown plugin", id)
|
|
return false
|
|
}
|
|
// A disabled plugin has no Loader, so setting openPanelIds would only
|
|
// produce an invisible "open" state that toggle() then has to unwind.
|
|
// Tell the caller plainly instead of silently no-op'ing.
|
|
if (!shell.pluginRegistry.isEnabled(id)) {
|
|
console.warn("summon: plugin not enabled, not summoning:", id)
|
|
return false
|
|
}
|
|
// Bar widgets take no payload; payloadJson is dropped on this path.
|
|
if (shell.isBarWidgetPanelPlugin(id)) {
|
|
var summoned = shell.bar && typeof shell.bar.summonBarWidget === "function"
|
|
&& shell.bar.summonBarWidget(id)
|
|
if (!summoned) console.warn("summon: no live bar widget for:", id)
|
|
return summoned === true
|
|
}
|
|
var next = ({})
|
|
for (var k in openPanelIds) next[k] = openPanelIds[k]
|
|
next[id] = true
|
|
openPanelIds = next
|
|
|
|
// Stash payload so the Loader.onLoaded handler can hand it to open().
|
|
var pending = ({})
|
|
for (var p in pendingPayloads) pending[p] = pendingPayloads[p].slice()
|
|
var queue = pending[id] || []
|
|
queue.push(payloadJson || "")
|
|
pending[id] = queue
|
|
pendingPayloads = pending
|
|
|
|
// If the plugin is keepLoaded and already mounted, deliver immediately.
|
|
deliverIfLoaded(id)
|
|
return true
|
|
}
|
|
|
|
function hide(pluginId) {
|
|
var id = shell.pluginRegistry.resolveEnabledId(pluginId)
|
|
if (!id) return false
|
|
if (shell.isBarWidgetPanelPlugin(id)) {
|
|
var hidden = shell.bar && typeof shell.bar.hideBarWidget === "function"
|
|
&& shell.bar.hideBarWidget(id)
|
|
if (!hidden) console.warn("hide: no live bar widget for:", id)
|
|
return hidden === true
|
|
}
|
|
invokeIfLoaded(id, "close", null)
|
|
if (!openPanelIds[id]) return true
|
|
var next = ({})
|
|
for (var k in openPanelIds) if (k !== id) next[k] = openPanelIds[k]
|
|
openPanelIds = next
|
|
return true
|
|
}
|
|
|
|
function isPluginOpen(pluginId) {
|
|
var id = shell.pluginRegistry.resolveEnabledId(pluginId)
|
|
if (shell.isBarWidgetPanelPlugin(id)) {
|
|
return shell.bar && typeof shell.bar.isBarWidgetOpen === "function"
|
|
? shell.bar.isBarWidgetOpen(id)
|
|
: false
|
|
}
|
|
var loader = panelLoaders[id]
|
|
if (loader && loader.item && loader.item.opened !== undefined)
|
|
return loader.item.opened === true
|
|
return openPanelIds[id] === true
|
|
}
|
|
|
|
function toggle(pluginId, payloadJson) {
|
|
var id = shell.pluginRegistry.resolveEnabledId(pluginId)
|
|
return isPluginOpen(id) ? hide(id) : summon(id, payloadJson)
|
|
}
|
|
|
|
// Map of pluginId -> Loader, populated by the Instantiator delegate below.
|
|
property var panelLoaders: ({})
|
|
|
|
function registerPanelLoader(pluginId, loader) {
|
|
var next = ({})
|
|
for (var k in panelLoaders) next[k] = panelLoaders[k]
|
|
next[pluginId] = loader
|
|
panelLoaders = next
|
|
deliverIfLoaded(pluginId)
|
|
}
|
|
|
|
function unregisterPanelLoader(pluginId) {
|
|
if (!panelLoaders[pluginId]) return
|
|
var next = ({})
|
|
for (var k in panelLoaders) if (k !== pluginId) next[k] = panelLoaders[k]
|
|
panelLoaders = next
|
|
}
|
|
|
|
function unloadPanels() {
|
|
for (var id in panelLoaders) hide(id)
|
|
panelEntries = []
|
|
panelLoaders = ({})
|
|
pendingPayloads = ({})
|
|
openPanelIds = ({})
|
|
}
|
|
|
|
function deliverIfLoaded(pluginId) {
|
|
var loader = panelLoaders[pluginId]
|
|
if (!loader || !loader.item) return
|
|
var queue = pendingPayloads[pluginId]
|
|
if (!Array.isArray(queue) || queue.length === 0) return
|
|
if (typeof loader.item.open === "function") {
|
|
for (var i = 0; i < queue.length; i++) {
|
|
try { loader.item.open(queue[i]) } catch (e) {
|
|
console.warn("plugin " + pluginId + " open() threw:", e)
|
|
}
|
|
}
|
|
}
|
|
var next = ({})
|
|
for (var k in pendingPayloads) if (k !== pluginId) next[k] = pendingPayloads[k].slice()
|
|
pendingPayloads = next
|
|
}
|
|
|
|
function invokeIfLoaded(pluginId, method, arg) {
|
|
var loader = panelLoaders[pluginId]
|
|
if (!loader || !loader.item) return
|
|
if (typeof loader.item[method] !== "function") return
|
|
try { loader.item[method](arg) } catch (e) {
|
|
console.warn("plugin " + pluginId + " " + method + "() threw:", e)
|
|
}
|
|
}
|
|
|
|
function callIfLoaded(pluginId, method, arg) {
|
|
var id = shell.pluginRegistry.resolveEnabledId(pluginId)
|
|
var loader = panelLoaders[id]
|
|
if (!loader || !loader.item) return "unknown"
|
|
if (typeof loader.item[method] !== "function") return "unknown"
|
|
try {
|
|
var result = loader.item[method](arg)
|
|
return result === undefined || result === null ? "ok" : String(result)
|
|
} catch (e) {
|
|
console.warn("plugin " + id + " " + method + "() threw:", e)
|
|
return "error"
|
|
}
|
|
}
|
|
|
|
// One Loader per discoverable panel/overlay/menu plugin. Active when the
|
|
// host marks it open. The Loader holds onto the instance while active so the
|
|
// plugin's FloatingWindow + state survive between summons within a session.
|
|
property var panelEntries: []
|
|
|
|
function computePanelEntries() {
|
|
var out = []
|
|
var plugins = shell.pluginRegistry.installedPlugins
|
|
var panelKinds = ["panel", "overlay", "menu"]
|
|
for (var id in plugins) {
|
|
var m = plugins[id]
|
|
if (!m || !Array.isArray(m.kinds)) continue
|
|
var matched = false
|
|
for (var i = 0; i < panelKinds.length; i++)
|
|
if (m.kinds.indexOf(panelKinds[i]) !== -1) { matched = true; break }
|
|
if (!matched) continue
|
|
if (!shell.pluginRegistry.isEnabled(id)) continue
|
|
var kind = m.kinds.indexOf("panel") !== -1 ? "panel"
|
|
: (m.kinds.indexOf("overlay") !== -1 ? "overlay" : "menu")
|
|
out.push({ id: id, manifest: m, kind: kind, keepLoaded: m.keepLoaded === true })
|
|
}
|
|
return out
|
|
}
|
|
|
|
Connections {
|
|
target: shell.pluginRegistry
|
|
function onPluginsChanged() { if (!shell.pluginReloading) shell.panelEntries = shell.computePanelEntries() }
|
|
}
|
|
|
|
Instantiator {
|
|
model: shell.panelEntries
|
|
active: true
|
|
|
|
delegate: QtObject {
|
|
id: panelEntry
|
|
required property var modelData
|
|
readonly property string pluginId: modelData.id
|
|
readonly property var manifest: modelData.manifest
|
|
readonly property string entryKind: modelData.kind
|
|
readonly property bool keepLoaded: modelData.keepLoaded === true
|
|
readonly property string sourceUrl: shell.pluginRegistry.entryPointUrl(manifest, entryKind)
|
|
|
|
property Loader panelLoader: Loader {
|
|
source: panelEntry.sourceUrl
|
|
active: panelEntry.sourceUrl !== "" && (panelEntry.keepLoaded || shell.openPanelIds[panelEntry.pluginId] === true)
|
|
asynchronous: true
|
|
onLoaded: {
|
|
if (!item) return
|
|
if ("omarchyPath" in item) item.omarchyPath = shell.omarchyPath
|
|
if ("shell" in item) item.shell = shell
|
|
if ("manifest" in item) item.manifest = panelEntry.manifest
|
|
if ("barWidgetRegistry" in item) item.barWidgetRegistry = shell.barWidgetRegistry
|
|
if ("pluginRegistry" in item) item.pluginRegistry = shell.pluginRegistry
|
|
// Plugins that pair a panel UI with a service entry read shared
|
|
// state off `service`. Hand them the matching singleton if one was
|
|
// loaded.
|
|
if ("service" in item) item.service = shell.serviceFor(panelEntry.pluginId)
|
|
shell.registerPanelLoader(panelEntry.pluginId, this)
|
|
}
|
|
onStatusChanged: {
|
|
if (status === Loader.Error) {
|
|
// Loader.errorString() reflects the source-load failure even when
|
|
// sourceComponent is null. Surface both so the user sees something
|
|
// actionable instead of a panel that silently refuses to open.
|
|
var detail = errorString && errorString() ? errorString() : ""
|
|
if (!detail && sourceComponent) detail = sourceComponent.errorString()
|
|
console.warn("panel plugin " + panelEntry.pluginId + " failed to load:", detail)
|
|
shell.hide(panelEntry.pluginId)
|
|
}
|
|
}
|
|
Component.onDestruction: shell.unregisterPanelLoader(panelEntry.pluginId)
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------- plugin loader
|
|
|
|
// Mirror plugin registry state into BarWidgetRegistry whenever it changes.
|
|
// Each enabled plugin with kind "bar-widget" gets a Component created from
|
|
// its manifest entry point and registered under its manifest id. Built-in
|
|
// widgets use the same first-party manifest contract as third-party widgets.
|
|
Connections {
|
|
target: shell.pluginRegistry
|
|
function onPluginsChanged() { if (!shell.pluginReloading) shell.syncPluginWidgets() }
|
|
}
|
|
|
|
property var pluginWidgetComponents: ({})
|
|
|
|
function syncPluginWidgets() {
|
|
var plugins = shell.pluginRegistry.installedPlugins
|
|
var seen = ({})
|
|
|
|
for (var pluginId in plugins) {
|
|
var manifest = plugins[pluginId]
|
|
if (!manifest || !manifest.kinds || manifest.kinds.indexOf("bar-widget") === -1) continue
|
|
if (!shell.pluginRegistry.isEnabled(pluginId)) continue
|
|
|
|
var registryKey = String(manifest.id)
|
|
seen[registryKey] = true
|
|
|
|
// Already loaded with matching source — leave it alone.
|
|
var existing = pluginWidgetComponents[registryKey]
|
|
var url = shell.pluginRegistry.entryPointUrl(manifest, "barWidget")
|
|
if (!url) {
|
|
console.warn("Plugin " + manifest.id + " has no barWidget entry point")
|
|
continue
|
|
}
|
|
var meta = manifest.barWidget || {}
|
|
meta = {
|
|
displayName: meta.displayName || manifest.name,
|
|
description: meta.description || manifest.description,
|
|
category: meta.category || "Plugin",
|
|
allowMultiple: meta.allowMultiple === true,
|
|
defaults: meta.defaults || {},
|
|
settingsForm: meta.settingsForm || "",
|
|
schema: meta.schema || [],
|
|
pluginId: manifest.id,
|
|
sourceDir: manifest.__sourceDir || "",
|
|
source: "plugin"
|
|
}
|
|
|
|
// A load already in flight for this URL registers itself when it
|
|
// finishes. Starting a second one produces a second Component for the
|
|
// same widget, and swapping a slot's component rebuilds its item —
|
|
// briefly running two of the widget, each registering its IPC handler.
|
|
if (existing && existing.url === url && !existing.component) continue
|
|
|
|
// If the component URL is unchanged, just refresh the metadata in
|
|
// place. We can't skip this even when the URL matches: manifests can
|
|
// change schema, defaults, or sourceDir between rescans, and the
|
|
// settings panel reads metadata from the registry.
|
|
if (existing && existing.url === url && shell.barWidgetRegistry.has(registryKey)) {
|
|
shell.barWidgetRegistry.register(registryKey, existing.component, meta)
|
|
continue
|
|
}
|
|
|
|
loadPluginWidget(registryKey, url, meta)
|
|
}
|
|
|
|
// Drop registrations for plugins that are no longer present or enabled.
|
|
var allIds = shell.barWidgetRegistry.availableIds()
|
|
for (var i = 0; i < allIds.length; i++) {
|
|
var id = allIds[i]
|
|
if (!pluginWidgetComponents[id]) continue
|
|
if (!seen[id]) {
|
|
shell.barWidgetRegistry.unregister(id)
|
|
var next = ({})
|
|
for (var k in pluginWidgetComponents) if (k !== id) next[k] = pluginWidgetComponents[k]
|
|
pluginWidgetComponents = next
|
|
}
|
|
}
|
|
}
|
|
|
|
function unloadPluginWidgets() {
|
|
for (var id in pluginWidgetComponents) shell.barWidgetRegistry.unregister(id)
|
|
pluginWidgetComponents = ({})
|
|
}
|
|
|
|
function reloadPlugins() {
|
|
if (shell.pluginReloading || shell.pluginRegistry.scanning) {
|
|
shell.pluginReloadPending = true
|
|
return
|
|
}
|
|
shell.pluginReloading = true
|
|
shell.unloadPanels()
|
|
shell.unloadPluginServices()
|
|
shell.unloadPluginWidgets()
|
|
Qt.callLater(shell.finishPluginReload)
|
|
}
|
|
|
|
function finishPluginReload() {
|
|
if (!shell.pluginReloading) return
|
|
if (shell.pluginRegistry.scanning) {
|
|
shell.pluginReloadPending = true
|
|
return
|
|
}
|
|
if (typeof Qt.clearComponentCache === "function") Qt.clearComponentCache()
|
|
shell.pluginRegistry.rescan()
|
|
}
|
|
|
|
Connections {
|
|
target: shell.pluginRegistry
|
|
function onLocalPluginChanged(pluginId) {
|
|
console.log("Local plugin changed, reloading:", pluginId)
|
|
localPluginReloadTimer.restart()
|
|
}
|
|
function onScanFinished() {
|
|
if (shell.pluginReloadPending) {
|
|
shell.pluginReloadPending = false
|
|
shell.pluginReloading = false
|
|
Qt.callLater(shell.reloadPlugins)
|
|
return
|
|
}
|
|
shell.pluginReloading = false
|
|
shell._syncServices()
|
|
shell.panelEntries = shell.computePanelEntries()
|
|
shell.syncPluginWidgets()
|
|
}
|
|
}
|
|
|
|
function setPluginWidgetComponent(registryKey, entry) {
|
|
var next = ({})
|
|
for (var k in pluginWidgetComponents) if (k !== registryKey) next[k] = pluginWidgetComponents[k]
|
|
if (entry) next[registryKey] = entry
|
|
pluginWidgetComponents = next
|
|
}
|
|
|
|
function loadPluginWidget(registryKey, url, meta) {
|
|
// Claim the key before the component exists. Qt.createComponent is
|
|
// asynchronous and syncPluginWidgets runs several times while the shell
|
|
// starts, so without a marker the later passes cannot tell a load in
|
|
// flight from one that never happened.
|
|
setPluginWidgetComponent(registryKey, { url: url, component: null })
|
|
|
|
var comp = Qt.createComponent(url, Component.Asynchronous)
|
|
function finalize() {
|
|
if (comp.status === Component.Ready) {
|
|
shell.barWidgetRegistry.register(registryKey, comp, meta)
|
|
shell.setPluginWidgetComponent(registryKey, { url: url, component: comp })
|
|
} else if (comp.status === Component.Error) {
|
|
console.warn("Plugin widget " + registryKey + " failed: " + comp.errorString())
|
|
// Drop the claim so a later rescan can retry.
|
|
shell.setPluginWidgetComponent(registryKey, null)
|
|
shell.pluginRegistry.pluginLoadFailed(registryKey, comp.errorString())
|
|
}
|
|
}
|
|
if (comp.status === Component.Loading) {
|
|
comp.statusChanged.connect(finalize)
|
|
} else {
|
|
finalize()
|
|
}
|
|
}
|
|
|
|
// --------------------------------------------------- image selector IPC
|
|
|
|
function imagePickerItem() {
|
|
var loader = panelLoaders["omarchy.image-picker"]
|
|
return loader && loader.item ? loader.item : null
|
|
}
|
|
|
|
IpcHandler {
|
|
target: "image-selector"
|
|
|
|
function open(imageDirs: string,
|
|
imageRowsB64: string,
|
|
selectedImage: string,
|
|
selectionFile: string,
|
|
doneFile: string,
|
|
showLabels: string,
|
|
filterable: string): string {
|
|
var payload = JSON.stringify({
|
|
imageDirs: imageDirs,
|
|
imageRows: Util.decodeBase64(imageRowsB64),
|
|
selectedImage: selectedImage,
|
|
selectionFile: selectionFile,
|
|
doneFile: doneFile,
|
|
showLabels: showLabels,
|
|
filterable: filterable
|
|
})
|
|
return shell.summon("omarchy.image-picker", payload) ? "ok" : "unknown"
|
|
}
|
|
|
|
function preload(imageRowsB64: string,
|
|
selectedImage: string,
|
|
showLabels: string,
|
|
filterable: string): string {
|
|
var picker = shell.imagePickerItem()
|
|
if (picker && typeof picker.preloadRows === "function") {
|
|
picker.preloadRows(Util.decodeBase64(imageRowsB64), selectedImage,
|
|
showLabels, filterable)
|
|
}
|
|
return "ok"
|
|
}
|
|
|
|
function cancel(doneFile: string): string {
|
|
var picker = shell.imagePickerItem()
|
|
if (picker && typeof picker.closeSelector === "function") {
|
|
picker.closeSelector(doneFile || "")
|
|
} else {
|
|
shell.hide("omarchy.image-picker")
|
|
}
|
|
return "ok"
|
|
}
|
|
|
|
function ping(): string {
|
|
return "ok"
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------- shell IPC
|
|
|
|
IpcHandler {
|
|
target: "shell"
|
|
|
|
function ping(): string {
|
|
return "ok"
|
|
}
|
|
|
|
function applyTheme(colorsB64: string, shellB64: string): string {
|
|
var colorsRaw = ""
|
|
var shellRaw = ""
|
|
try { colorsRaw = Qt.atob(String(colorsB64 || "")) } catch (e) { colorsRaw = "" }
|
|
try { shellRaw = Qt.atob(String(shellB64 || "")) } catch (e2) { shellRaw = "" }
|
|
Color.loadColors(colorsRaw)
|
|
Color.loadShell(shellRaw)
|
|
Style.scheduleRefresh()
|
|
return "ok"
|
|
}
|
|
|
|
function rescanPlugins(): void {
|
|
shell.reloadPlugins()
|
|
}
|
|
|
|
function reloadConfig(): string {
|
|
userConfigFile.reload()
|
|
return "ok"
|
|
}
|
|
|
|
function toggleBarTransparency(): string {
|
|
if (shell.bar && typeof shell.bar.toggleTransparency === "function") {
|
|
shell.bar.toggleTransparency()
|
|
return "ok"
|
|
}
|
|
return "no-bar"
|
|
}
|
|
|
|
function setPluginEnabled(id: string, enabled: string): string {
|
|
return shell.pluginRegistry.setEnabled(id, enabled === "true") ? "ok" : "unknown"
|
|
}
|
|
|
|
function enablePlugin(id: string, placementJson: string): string {
|
|
try {
|
|
var placement = JSON.parse(placementJson || "{}")
|
|
if (shell.pluginRegistry.setEnabled(id, true, placement)) return "ok"
|
|
return shell.pluginRegistry.lastEnableError || "unknown"
|
|
} catch (e) {
|
|
return "invalid placement: " + e
|
|
}
|
|
}
|
|
|
|
// Enable, but only where the widget is not on the bar already, so a caller
|
|
// that cannot know whether it ran before leaves a placed widget alone.
|
|
function putBarWidget(id: string, placementJson: string): string {
|
|
try {
|
|
var error = shell.pluginRegistry.putBarWidget(id, JSON.parse(placementJson || "{}"))
|
|
return error ? error : "ok"
|
|
} catch (e) {
|
|
return "invalid placement: " + e
|
|
}
|
|
}
|
|
|
|
function moveBarWidget(id: string, placementJson: string): string {
|
|
try {
|
|
var error = shell.pluginRegistry.moveBarWidget(id, JSON.parse(placementJson || "{}"))
|
|
return error ? error : "ok"
|
|
} catch (e) {
|
|
return "invalid placement: " + e
|
|
}
|
|
}
|
|
|
|
function setBarWidget(id: string, key: string, valueJson: string, selectorJson: string): string {
|
|
try {
|
|
var value = JSON.parse(valueJson)
|
|
var selector = JSON.parse(selectorJson || "{}")
|
|
var error = shell.pluginRegistry.setBarWidget(id, key, value, selector)
|
|
return error ? error : "ok"
|
|
} catch (e) {
|
|
return "invalid widget setting: " + e
|
|
}
|
|
}
|
|
|
|
function listPlugins(): string {
|
|
var out = []
|
|
var plugins = shell.pluginRegistry.installedPlugins
|
|
for (var id in plugins) {
|
|
var kinds = plugins[id].kinds || []
|
|
var isBarOption = Array.isArray(kinds) && kinds.indexOf("bar") !== -1
|
|
var isBarWidget = Array.isArray(kinds) && kinds.indexOf("bar-widget") !== -1
|
|
var active = isBarOption && shell.isActiveBarOption(id)
|
|
var metadata = plugins[id].omarchy
|
|
var clonedFrom = Util.isPlainObject(metadata) ? String(metadata.clonedFrom || "") : ""
|
|
out.push({
|
|
id: id,
|
|
name: plugins[id].name,
|
|
kinds: kinds,
|
|
// What `omarchy plugin enable/disable` toggles: for a widget that is
|
|
// its place in the bar, not whether its component is loadable.
|
|
enabled: isBarOption ? active
|
|
: (isBarWidget ? shell.pluginRegistry.inBar(id) : shell.pluginRegistry.isEnabled(id)),
|
|
active: active,
|
|
// A bar has no off, only a successor: you leave one by enabling
|
|
// another, so there is nothing for disable to do to it. Said here so
|
|
// that a caller offering the verbs does not have to read kinds and
|
|
// work it out again.
|
|
canDisable: !isBarOption,
|
|
firstParty: !!plugins[id].__isFirstParty,
|
|
clonedFrom: clonedFrom
|
|
})
|
|
}
|
|
// Consumers should not each invent their own presentation order.
|
|
out.sort(function(left, right) {
|
|
var leftName = String(left.name || left.id)
|
|
var rightName = String(right.name || right.id)
|
|
if (leftName < rightName) return -1
|
|
if (leftName > rightName) return 1
|
|
return String(left.id).localeCompare(String(right.id))
|
|
})
|
|
return JSON.stringify(out)
|
|
}
|
|
|
|
// Returns the effective shell.json content as JSON. Useful for debugging
|
|
// and for CLI tools that want to inspect the merged state without
|
|
// re-implementing the load logic.
|
|
function listShellConfig(): string {
|
|
return JSON.stringify(shell.shellConfig || {})
|
|
}
|
|
|
|
function debugBarGeometry(): string {
|
|
return JSON.stringify(shell.bar && shell.bar.debugBarGeometry ? shell.bar.debugBarGeometry() : [])
|
|
}
|
|
|
|
function summon(id: string, payloadJson: string): string {
|
|
return shell.summon(id, payloadJson) ? "ok" : "unknown"
|
|
}
|
|
|
|
function hide(id: string): void {
|
|
shell.hide(id)
|
|
}
|
|
|
|
function toggle(id: string, payloadJson: string): void {
|
|
shell.toggle(id, payloadJson)
|
|
}
|
|
|
|
// A bar section's panels answer to their position as well as their id, so a
|
|
// hotkey can mean "the third panel in the right section" and keep meaning
|
|
// it after the bar is rearranged. Returns the id it acted on, or "unknown"
|
|
// when the section holds no panel at that position.
|
|
function togglePanelAt(section: string, index: string): string {
|
|
var id = shell.bar && typeof shell.bar.panelWidgetIdAt === "function"
|
|
? shell.bar.panelWidgetIdAt(section, index)
|
|
: ""
|
|
if (!id) return "unknown"
|
|
shell.toggle(id, "{}")
|
|
return id
|
|
}
|
|
|
|
function call(id: string, method: string, arg: string): string {
|
|
return shell.callIfLoaded(id, method, arg)
|
|
}
|
|
}
|
|
}
|