Enable plugin hot reloading for add / remove
This commit is contained in:
+23
-1
@@ -94,6 +94,21 @@ require_command() {
|
||||
command -v "$command_name" >/dev/null 2>&1 || fail "$command_name is required"
|
||||
}
|
||||
|
||||
plugin_discovered() {
|
||||
local id="$1" plugins
|
||||
plugins=$(omarchy-shell shell listPlugins 2>/dev/null) || return 1
|
||||
jq -e --arg id "$id" 'any(.[]; .id == $id)' <<<"$plugins" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
wait_for_plugin_discovery() {
|
||||
local id="$1" attempt
|
||||
for (( attempt = 0; attempt < 40; attempt++ )); do
|
||||
plugin_discovered "$id" && return 0
|
||||
sleep 0.05
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
section_valid() {
|
||||
[[ $1 =~ ^(left|center|right)$ ]]
|
||||
}
|
||||
@@ -181,7 +196,14 @@ plugin_enabled() {
|
||||
id=$(canonical_widget_id "$id")
|
||||
|
||||
omarchy-shell shell rescanPlugins >/dev/null 2>&1 || true
|
||||
omarchy-shell shell setPluginEnabled "$id" "$enabled" || fail "could not update plugin; is omarchy-shell running?"
|
||||
if [[ $enabled == "true" ]]; then
|
||||
require_command jq
|
||||
wait_for_plugin_discovery "$id" || fail "plugin '$id' was not discovered; is omarchy-shell running?"
|
||||
fi
|
||||
|
||||
local result
|
||||
result=$(omarchy-shell shell setPluginEnabled "$id" "$enabled") || fail "could not update plugin; is omarchy-shell running?"
|
||||
[[ $result == "ok" ]] || fail "plugin '$id' is not known; run: omarchy plugin rescan"
|
||||
|
||||
if [[ $enabled == "true" && $# -gt 0 ]]; then
|
||||
mutate_bar move --id "$id" "$@"
|
||||
|
||||
+18
-1
@@ -29,6 +29,21 @@ interactive() {
|
||||
[[ -t 0 && -t 1 ]]
|
||||
}
|
||||
|
||||
plugin_discovered() {
|
||||
local id="$1" plugins
|
||||
plugins=$(omarchy-shell shell listPlugins 2>/dev/null) || return 1
|
||||
jq -e --arg id "$id" 'any(.[]; .id == $id)' <<<"$plugins" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
wait_for_plugin_discovery() {
|
||||
local id="$1" attempt
|
||||
for (( attempt = 0; attempt < 40; attempt++ )); do
|
||||
plugin_discovered "$id" && return 0
|
||||
sleep 0.05
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
PLUGIN_ID=""
|
||||
FROM_SOURCE=""
|
||||
ENABLE_AFTER="" # "", "true", or "false"
|
||||
@@ -280,7 +295,9 @@ if [[ -z $ENABLE_AFTER ]]; then
|
||||
fi
|
||||
|
||||
if [[ $ENABLE_AFTER == true ]]; then
|
||||
if omarchy-shell shell setPluginEnabled "$m_id" true >/dev/null 2>&1; then
|
||||
if ! wait_for_plugin_discovery "$m_id"; then
|
||||
echo "Could not enable $m_id because omarchy-shell did not discover it yet. Enable later with: omarchy plugin enable $m_id" >&2
|
||||
elif result=$(omarchy-shell shell setPluginEnabled "$m_id" true) && [[ $result == "ok" ]]; then
|
||||
echo "Enabled $m_id."
|
||||
if [[ $m_kinds == *bar-widget* ]]; then
|
||||
echo "It was added to the bar; arrange it with: omarchy plugin bar move $m_id --section <left|center|right>"
|
||||
|
||||
@@ -102,6 +102,5 @@ fi
|
||||
omarchy-shell shell rescanPlugins >/dev/null 2>&1 || true
|
||||
|
||||
if [[ $was_enabled == "true" ]]; then
|
||||
echo "Plugin was enabled; restart the shell to fully unload it:"
|
||||
echo " omarchy restart shell"
|
||||
echo "Plugin was enabled and was unloaded from omarchy-shell."
|
||||
fi
|
||||
|
||||
@@ -208,8 +208,7 @@ done
|
||||
|
||||
if ((any_enabled)); then
|
||||
echo
|
||||
echo "Updated plugins that were enabled may need a shell restart to fully reload:"
|
||||
echo " omarchy restart shell"
|
||||
echo "Updated enabled plugins were hot-reloaded by omarchy-shell."
|
||||
fi
|
||||
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user