fix(phone-connect): zh-Hans locale, aliasMap, box padding, volume, config data loss, interval, dead settings, slider, UI issues (#199)

* fix(phone-connect): zh-Hans locale, switcher aliasMap, box padding

- Rename zh_hans -> zh-Hans (plugin.toml value, en.json key) and add
  the missing translations/zh-Hans.json. The zh_hans tag does not match
  BCP 47, so the framework's materialize step dropped the Chinese
  translation file and t() returned raw dot keys in the UI.
- Add missing aliasMap definition in switcher() so the multi-device
  panel no longer errors on aliasMap[id]. Fixes #176.
- Replace ui.box({padding=...}) with ui.row({padding=...}); box does
  not support the padding prop, causing ui-tree warnings on open.

Supersedes #190 (which covers only the aliasMap fix).

* fix(phone-connect): volume quoting, config data loss, interval, dead settings, slider, UI issues

1. media_set_volume: shellQuote the <int32> variant arg (was unquoted,
   shell treated < as redirect; same fix as media_seek).
2. onConfigChanged: track last-applied custom_image/device_alias values
   so unrelated config edits (e.g. language switch) no longer wipe a
   device's image/alias. Seed trackers at init so reload is safe too.
3. state_update_interval=0: return 3600000ms + guard in update() to
   skip auto-refresh, matching the '0 disables' description.
4. Remove 4 dead settings (show_ongoing_media, show_device_placeholder,
   scan_subdirectories, max_recent_images) declared but never read,
   plus orphan recent_images translation keys.
5. Media slider: freeze value during drag via per-device dragState so
   the 1s service refresh doesn't yank the slider back. Also fixes
   onDragEnd seeking to a stale seekPos.
6. Minor: runCli reports cli_failed not no_backend; browse uses runAsync
   not runInTerminal; charging color priority over low-battery; device
   name falls back to d.name; fix comment mismatches.

* chore: bump version to 0.1.1

* fix: use lowercase zh-hans translation key to pass CI validation

CI rejects uppercase in translation keys (zh-Hans). The translation key
and label_key are now lowercase zh-hans, while the file name stays
zh-Hans.json (required by the framework's materialize step) and the
select value stays zh-Hans (used to build the file path).
This commit is contained in:
CSY2569
2026-08-01 08:56:54 -04:00
committed by GitHub
parent efa9d61f4c
commit 16d66a5b18
6 changed files with 237 additions and 157 deletions
+23 -8
View File
@@ -15,6 +15,13 @@ local function t(key)
return table[key] or key
end
-- Track last-applied config values so onConfigChanged only re-applies
-- custom_image / device_alias when they actually change, not on every
-- unrelated config edit (e.g. language switch). Prevents wiping a
-- device's image/alias that was set via the global setting.
local lastCustomImage = nil
local lastDeviceAlias = nil
-- ── State contract (read by UI entries) ──────────────────────────────────────
-- noctalia.state "pc.backend" : { available=bool, name="KDE Connect"|"None",
-- announcedName="", selfId="" }
@@ -484,7 +491,7 @@ end
local function runCli(args, cb)
noctalia.runAsync("kdeconnect-cli " .. args, function(res)
if res and res.error then
noctalia.notifyError(t("error.no_backend"), res.error)
noctalia.notifyError(t("error.cli_failed"), res.error)
end
if cb then cb(res) end
end)
@@ -596,7 +603,7 @@ local function handleCommand(cmd)
local first = (res.stdout or ""):match("'([^']+)'")
if first then dirPath = first end
end
noctalia.runInTerminal("xdg-open " .. shellQuote(dirPath))
noctalia.runAsync("xdg-open " .. shellQuote(dirPath), function() end)
noctalia.notify(t("notify.opening_browser"), dirPath)
end)
end)
@@ -664,7 +671,7 @@ local function handleCommand(cmd)
.. " --object-path " .. shellQuote(path)
.. " --method " .. shellQuote(PROPS_IFACE .. ".Set")
.. " " .. shellQuote(MPRIS_IFACE) .. " volume "
.. "<int32 " .. tostring(vol) .. ">",
.. shellQuote("<int32 " .. tostring(vol) .. ">"),
function() refreshDevices() end)
else
noctalia.log("[phone-connect] unknown cmd op: " .. tostring(op))
@@ -682,7 +689,7 @@ end
-- ── Lifecycle ────────────────────────────────────────────────────────────────
local function intervalMs()
local secs = tonumber(noctalia.getConfig("state_update_interval")) or 30
if secs <= 0 then return 60000 end
if secs <= 0 then return 3600000 end -- disabled: large interval to minimize wakeups
-- if media is playing, poll faster for live position updates
for _, d in pairs(devices) do
if d.mediaisPlaying == true then return 1000 end
@@ -691,16 +698,19 @@ local function intervalMs()
end
function update()
local secs = tonumber(noctalia.getConfig("state_update_interval")) or 30
noctalia.setUpdateInterval(intervalMs())
if secs <= 0 then return end -- disabled: skip auto-refresh
detectBackend()
refreshDevices()
end
function onConfigChanged()
noctalia.setUpdateInterval(intervalMs())
-- apply custom_image to selected device
-- apply custom_image to selected device (only when actually changed)
local img = noctalia.getConfig("custom_image")
if img ~= nil then
if img ~= nil and img ~= lastCustomImage then
lastCustomImage = img
local sel = noctalia.state.get("pc.selected")
if sel and sel ~= "" then
local map = noctalia.state.get("pc.imageMap") or {}
@@ -709,9 +719,10 @@ function onConfigChanged()
persistImageMap(map)
end
end
-- apply device_alias to selected device
-- apply device_alias to selected device (only when actually changed)
local alias = noctalia.getConfig("device_alias")
if alias ~= nil then
if alias ~= nil and alias ~= lastDeviceAlias then
lastDeviceAlias = alias
local sel = noctalia.state.get("pc.selected")
if sel and sel ~= "" then
local amap = noctalia.state.get("pc.aliasMap") or {}
@@ -744,6 +755,10 @@ function onIpc(event, payload)
end
-- Top-level init runs once at load.
-- Seed config trackers so the first onConfigChanged after reload doesn't
-- re-apply default custom_image/device_alias and wipe a device's image/alias.
lastCustomImage = noctalia.getConfig("custom_image") or ""
lastDeviceAlias = noctalia.getConfig("device_alias") or ""
detectBackend()
refreshDevices()
-- Command channel: UI entries write { op, device, seq, ... } to "pc.cmd".