Commit 1b56727
Changed files (2)
modules
desktop
noctalia
plugins
phone-connect
modules/desktop/noctalia/plugins/phone-connect/phone-connect.patch
@@ -0,0 +1,148 @@
+diff -ruN a/plugin.toml b/plugin.toml
+--- a/plugin.toml 2026-10-13 10:23:24.611263961 +0800
++++ b/plugin.toml 2026-10-13 10:23:24.612151446 +0800
+@@ -51,6 +51,20 @@
+ default = false
+
+ [[setting]]
++key = "hide_when_offline"
++type = "bool"
++label_key = "settings.hide_when_offline.label"
++description_key = "settings.hide_when_offline.description"
++default = false
++
++[[setting]]
++key = "auto_select_online"
++type = "bool"
++label_key = "settings.auto_select_online.label"
++description_key = "settings.auto_select_online.description"
++default = true
++
++[[setting]]
+ key = "battery_display"
+ type = "select"
+ label_key = "settings.battery_display.label"
+diff -ruN a/service.luau b/service.luau
+--- a/service.luau 2026-10-13 10:23:24.611276193 +0800
++++ b/service.luau 2026-10-13 10:23:24.612157136 +0800
+@@ -161,6 +161,8 @@
+ -- In-memory device table keyed by id (mirrors original PhoneConnectService.devices).
+ local devices= {}
+ local deviceOrder= {}
++-- forward-declared: assigned below once persistSelected exists
++local autoSelectOnline
+ -- forward-declared: fetchMpris re-evaluates the poll interval; the definition
+ -- lives in the Lifecycle section below.
+ local intervalMs
+@@ -177,6 +179,7 @@
+ local function publishDevices()
+ noctalia.state.set("pc.devices", snapshotDevices())
+ noctalia.state.set("pc.order", deviceOrder)
++ if autoSelectOnline then autoSelectOnline() end
+ end
+
+ -- ── Persistent state (selected device) ──────────────────────────────────────
+@@ -216,6 +219,24 @@
+ saveData(data)
+ end
+
++ -- Never override a selection that is already online, so a manual pick sticks.
++ autoSelectOnline = function()
++ if noctalia.getConfig("auto_select_online") ~= true then return end
++ local sel = noctalia.state.get("pc.selected")
++ local cur = sel and devices[sel]
++ if cur and cur.isPaired == true and cur.isReachable == true then return end
++ for _, id in ipairs(deviceOrder) do
++ local d = devices[id]
++ if d and d.isPaired == true and d.isReachable == true then
++ if sel ~= id then
++ noctalia.state.set("pc.selected", id)
++ persistSelected(id)
++ end
++ return
++ end
++ end
++ end
++
+ local function persistImageMap(map)
+ local data = loadData()
+ data.imageMap = map
+diff -ruN a/translations/en.json b/translations/en.json
+--- a/translations/en.json 2026-10-13 10:23:24.611362840 +0800
++++ b/translations/en.json 2026-10-13 10:23:24.612202053 +0800
+@@ -71,6 +71,10 @@
+ "unpaired": "Unpaired"
+ },
+ "settings": {
++ "auto_select_online": {
++ "description": "Automatically select the first online device while the current selection is offline.",
++ "label": "Auto-select Online Device"
++ },
+ "battery_display": {
+ "description": "Choose whether the bar widget shows the battery icon, percentage, both, or neither.",
+ "hidden": "Hidden",
+@@ -95,6 +99,10 @@
+ "description": "Show a quick action to send the clipboard to the device.",
+ "label": "Show Clipboard Action"
+ },
++ "hide_when_offline": {
++ "description": "Hide the bar widget entirely while no device is connected.",
++ "label": "Hide When Offline"
++ },
+ "language": {
+ "description": "Display language",
+ "en": "English",
+diff -ruN a/translations/zh-Hans.json b/translations/zh-Hans.json
+--- a/translations/zh-Hans.json 2026-10-13 10:23:24.611373924 +0800
++++ b/translations/zh-Hans.json 2026-10-13 10:23:24.612212356 +0800
+@@ -69,6 +69,10 @@
+ "unpaired": "未配对"
+ },
+ "settings": {
++ "auto_select_online": {
++ "description": "当前选中设备离线时,自动选择第一个在线的设备。",
++ "label": "自动选择在线设备"
++ },
+ "battery_display": {
+ "description": "选择栏部件显示电池图标、百分比、两者或都不显示。",
+ "hidden": "隐藏",
+@@ -93,6 +97,10 @@
+ "description": "显示一键发送剪贴板到设备的快捷操作。",
+ "label": "显示剪贴板操作"
+ },
++ "hide_when_offline": {
++ "description": "没有设备连接时完全隐藏栏部件。",
++ "label": "离线时隐藏"
++ },
+ "language": {
+ "description": "显示语言。",
+ "en": "English",
+diff -ruN a/widget.luau b/widget.luau
+--- a/widget.luau 2026-10-13 10:23:24.611378697 +0800
++++ b/widget.luau 2026-10-13 10:23:24.612217417 +0800
+@@ -54,8 +54,25 @@
+ return nil
+ end
+
++local function anyOnline()
++ local devices = noctalia.state.get("pc.devices") or {}
++ local order = noctalia.state.get("pc.order") or {}
++ for _, id in ipairs(order) do
++ local d = devices[id]
++ if d and d.isPaired == true and d.isReachable == true then return true end
++ end
++ return false
++end
++
+ local function render()
+ local backend = noctalia.state.get("pc.backend") or { available = false }
++
++ if noctalia.getConfig("hide_when_offline") == true and not anyOnline() then
++ barWidget.setVisible(false)
++ return
++ end
++ barWidget.setVisible(true)
++
+ local d = selectedDevice()
+ local enableCharging = noctalia.getConfig("enable_charging_animation")
+ local showDeviceName = noctalia.getConfig("show_device_name") == true
modules/desktop/noctalia/default.nix
@@ -26,6 +26,12 @@
hash = "sha256-DVlvf1bjUia35aOo7M7LKQxTS+xTkF0OpqzJHK3qjWk=";
};
+ # Adds "hide when offline" and "auto-select online" to the upstream plugin.
+ phoneConnect = pkgs.runCommand "phone-connect-patched" {} ''
+ cp -r --no-preserve=mode ${communityPlugins}/phone-connect $out
+ ${lib.getExe pkgs.patch} -p1 -d $out < ${./plugins/phone-connect/phone-connect.patch}
+ '';
+
plugins =
{
"noctalia/kaomoji".src = "${officialPlugins}/kaomoji";
@@ -34,7 +40,7 @@
(host.hasAspect den.aspects.desktop.app.kdeconnect)
{
"icefish/phone-connect" = {
- src = "${communityPlugins}/phone-connect";
+ src = "${phoneConnect}";
systemDeps = [pkgs.glib.bin pkgs.sshfs];
};
});
@@ -89,6 +95,8 @@
};
plugin_settings = {
"icefish/phone-connect".language = "zh-Hans";
+ "icefish/phone-connect".hide_when_offline = true;
+ "icefish/phone-connect".auto_select_online = true;
};
bar = {
order = ["default"];