Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Play on phone: a switch on Home, next to Phone as speaker

Bee8d836616d363
diff --git a/desktop/app/build.rs b/desktop/app/build.rs
index 31a5a51..adedcbe 100644
--- a/desktop/app/build.rs
+++ b/desktop/app/build.rs
@@ -52,6 +52,7 @@ const QML: &[&str] = &[
"qml/components/Toggle.qml",
"qml/components/TransferItem.qml",
"qml/components/ValueSlider.qml",
+ "qml/components/SwitchBar.qml",
"qml/components/Txt.qml",
"qml/pages/AppsPage.qml",
"qml/pages/CallsPage.qml",
diff --git a/desktop/app/i18n/nectarlink_zh_CN.ts b/desktop/app/i18n/nectarlink_zh_CN.ts
index 02baaa9..b57d4d0 100644
--- a/desktop/app/i18n/nectarlink_zh_CN.ts
+++ b/desktop/app/i18n/nectarlink_zh_CN.ts
@@ -1680,7 +1680,7 @@
</message>
<message>
<location filename="../qml/pages/HomePage.qml" line="1243"/>
- <location filename="../qml/pages/HomePage.qml" line="3461"/>
+ <location filename="../qml/pages/HomePage.qml" line="3426"/>
<source>Send files</source>
<translation>发送文件</translation>
</message>
@@ -1696,7 +1696,7 @@
</message>
<message>
<location filename="../qml/pages/HomePage.qml" line="1262"/>
- <location filename="../qml/pages/HomePage.qml" line="2740"/>
+ <location filename="../qml/pages/HomePage.qml" line="2705"/>
<source>Clipboard history</source>
<translation>剪贴板历史记录</translation>
</message>
@@ -1787,14 +1787,14 @@
</message>
<message>
<location filename="../qml/pages/HomePage.qml" line="1492"/>
- <location filename="../qml/pages/HomePage.qml" line="2104"/>
- <location filename="../qml/pages/HomePage.qml" line="2196"/>
+ <location filename="../qml/pages/HomePage.qml" line="2069"/>
+ <location filename="../qml/pages/HomePage.qml" line="2161"/>
<source>Cancel</source>
<translation>取消</translation>
</message>
<message>
<location filename="../qml/pages/HomePage.qml" line="1527"/>
- <location filename="../qml/pages/HomePage.qml" line="2456"/>
+ <location filename="../qml/pages/HomePage.qml" line="2421"/>
<source>Timeline</source>
<translation>时间线</translation>
</message>
@@ -1865,7 +1865,7 @@
</message>
<message>
<location filename="../qml/pages/HomePage.qml" line="1826"/>
- <location filename="../qml/pages/HomePage.qml" line="2308"/>
+ <location filename="../qml/pages/HomePage.qml" line="2273"/>
<source>Stop</source>
<translation>停止</translation>
</message>
@@ -1940,333 +1940,352 @@
<translation>即时热点</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2046"/>
- <location filename="../qml/pages/HomePage.qml" line="2064"/>
+ <location filename="../qml/pages/HomePage.qml" line="2013"/>
<source>Phone as speaker</source>
<translation>手机作为扬声器</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2055"/>
+ <location filename="../qml/pages/HomePage.qml" line="2014"/>
<source>Streaming PC audio</source>
<translation>正在传输电脑音频</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2095"/>
+ <location filename="../qml/pages/HomePage.qml" line="2025"/>
+ <source>Play on phone</source>
+ <translation>在手机上播放</translation>
+ </message>
+ <message>
+ <location filename="../qml/pages/HomePage.qml" line="2028"/>
+ <source>Watching on %1</source>
+ <translation>正在 %1 上观看</translation>
+ </message>
+ <message>
+ <location filename="../qml/pages/HomePage.qml" line="2029"/>
+ <source>Tap the notification on %1</source>
+ <translation>轻触 %1 上的通知</translation>
+ </message>
+ <message>
+ <location filename="../qml/pages/HomePage.qml" line="2031"/>
+ <source>Play a video on this PC first</source>
+ <translation>请先在此电脑上播放视频</translation>
+ </message>
+ <message>
+ <location filename="../qml/pages/HomePage.qml" line="2060"/>
<source>Turning off Wi‑Fi may disconnect %1.</source>
<translation>关闭 Wi‑Fi 可能会断开 %1。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2110"/>
+ <location filename="../qml/pages/HomePage.qml" line="2075"/>
<source>Turn off</source>
<translation>关闭</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2135"/>
+ <location filename="../qml/pages/HomePage.qml" line="2100"/>
<source>Ring</source>
<translation>响铃</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2136"/>
+ <location filename="../qml/pages/HomePage.qml" line="2101"/>
<source>Vibrate</source>
<translation>振动</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2137"/>
+ <location filename="../qml/pages/HomePage.qml" line="2102"/>
<source>Silent</source>
<translation>静音</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2154"/>
+ <location filename="../qml/pages/HomePage.qml" line="2119"/>
<source>Volume</source>
<translation>音量</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2165"/>
+ <location filename="../qml/pages/HomePage.qml" line="2130"/>
<source>Brightness</source>
<translation>亮度</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2186"/>
+ <location filename="../qml/pages/HomePage.qml" line="2151"/>
<source>Continuity Camera</source>
<translation>接续相机</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2197"/>
+ <location filename="../qml/pages/HomePage.qml" line="2162"/>
<source>Scan document</source>
<translation>扫描文档</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2210"/>
+ <location filename="../qml/pages/HomePage.qml" line="2175"/>
<source>Phone as webcam</source>
<translation>手机作为摄像头</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2213"/>
+ <location filename="../qml/pages/HomePage.qml" line="2178"/>
<source>Streaming</source>
<translation>正在传输</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2284"/>
+ <location filename="../qml/pages/HomePage.qml" line="2249"/>
<source>Type on phone</source>
<translation>在手机上输入</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2295"/>
+ <location filename="../qml/pages/HomePage.qml" line="2260"/>
<source>Sent: %1</source>
<translation>已发送:%1</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2296"/>
+ <location filename="../qml/pages/HomePage.qml" line="2261"/>
<source>Listening for keys</source>
<translation>正在监听按键</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2297"/>
- <location filename="../qml/pages/HomePage.qml" line="3057"/>
+ <location filename="../qml/pages/HomePage.qml" line="2262"/>
+ <location filename="../qml/pages/HomePage.qml" line="3022"/>
<source>When connected</source>
<translation>连接后</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2308"/>
+ <location filename="../qml/pages/HomePage.qml" line="2273"/>
<source>Start</source>
<translation>开始</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2356"/>
- <location filename="../qml/pages/HomePage.qml" line="2423"/>
+ <location filename="../qml/pages/HomePage.qml" line="2321"/>
+ <location filename="../qml/pages/HomePage.qml" line="2388"/>
<source>Clipboard</source>
<translation>剪贴板</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2403"/>
+ <location filename="../qml/pages/HomePage.qml" line="2368"/>
<source>Type here: keys go to %1</source>
<translation>在此输入:按键将发送到 %1</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2404"/>
+ <location filename="../qml/pages/HomePage.qml" line="2369"/>
<source>Click to focus keyboard</source>
<translation>点击以聚焦键盘</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2411"/>
+ <location filename="../qml/pages/HomePage.qml" line="2376"/>
<source>Ctrl+V pastes · Esc stops</source>
<translation>Ctrl+V 粘贴 · Esc 停止</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2420"/>
+ <location filename="../qml/pages/HomePage.qml" line="2385"/>
<source>Paste</source>
<translation>粘贴</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2465"/>
+ <location filename="../qml/pages/HomePage.qml" line="2430"/>
<source>View all</source>
<translation>查看全部</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2475"/>
+ <location filename="../qml/pages/HomePage.qml" line="2440"/>
<source>No recent activity</source>
<translation>没有最近活动</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2564"/>
+ <location filename="../qml/pages/HomePage.qml" line="2529"/>
<source>%1 notifications</source>
<translation>%1 条通知</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2567"/>
+ <location filename="../qml/pages/HomePage.qml" line="2532"/>
<source>Show</source>
<translation>显示</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2568"/>
+ <location filename="../qml/pages/HomePage.qml" line="2533"/>
<source>No pop-ups</source>
<translation>不弹出提示</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2569"/>
+ <location filename="../qml/pages/HomePage.qml" line="2534"/>
<source>Hide</source>
<translation>隐藏</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2583"/>
+ <location filename="../qml/pages/HomePage.qml" line="2548"/>
<source>Hidden on this PC.</source>
<translation>已在本机隐藏。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2585"/>
+ <location filename="../qml/pages/HomePage.qml" line="2550"/>
<source>Shown in feed without pop-ups.</source>
<translation>在信息流中显示,但不弹出提示。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2586"/>
+ <location filename="../qml/pages/HomePage.qml" line="2551"/>
<source>Shown in feed and as Windows pop-ups.</source>
<translation>在信息流中显示,并作为 Windows 弹窗提示。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2590"/>
- <location filename="../qml/pages/HomePage.qml" line="2717"/>
- <location filename="../qml/pages/HomePage.qml" line="2960"/>
- <location filename="../qml/pages/HomePage.qml" line="3538"/>
+ <location filename="../qml/pages/HomePage.qml" line="2555"/>
+ <location filename="../qml/pages/HomePage.qml" line="2682"/>
+ <location filename="../qml/pages/HomePage.qml" line="2925"/>
+ <location filename="../qml/pages/HomePage.qml" line="3503"/>
<source>Done</source>
<translation>完成</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2609"/>
+ <location filename="../qml/pages/HomePage.qml" line="2574"/>
<source>Notification history</source>
<translation>通知历史记录</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2617"/>
- <location filename="../qml/pages/HomePage.qml" line="2748"/>
+ <location filename="../qml/pages/HomePage.qml" line="2582"/>
+ <location filename="../qml/pages/HomePage.qml" line="2713"/>
<source>Clear history</source>
<translation>清除历史记录</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2627"/>
+ <location filename="../qml/pages/HomePage.qml" line="2592"/>
<source>Dismissed notifications from the last 24 hours.</source>
<translation>最近 24 小时内已忽略的通知。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2628"/>
+ <location filename="../qml/pages/HomePage.qml" line="2593"/>
<source>No recent notifications.</source>
<translation>没有最近的通知。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2670"/>
- <location filename="../qml/pages/HomePage.qml" line="2676"/>
+ <location filename="../qml/pages/HomePage.qml" line="2635"/>
+ <location filename="../qml/pages/HomePage.qml" line="2641"/>
<source>Search notification history</source>
<translation>搜索通知历史记录</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2713"/>
- <location filename="../qml/pages/HomePage.qml" line="2956"/>
+ <location filename="../qml/pages/HomePage.qml" line="2678"/>
+ <location filename="../qml/pages/HomePage.qml" line="2921"/>
<source>Nothing matches “%1”.</source>
<translation>没有匹配“%1”的内容。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2758"/>
+ <location filename="../qml/pages/HomePage.qml" line="2723"/>
<source>Last 50 shared clips.</source>
<translation>最近 50 条共享剪贴内容。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2759"/>
+ <location filename="../qml/pages/HomePage.qml" line="2724"/>
<source>No shared clips yet.</source>
<translation>还没有共享的剪贴内容。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2799"/>
- <location filename="../qml/pages/HomePage.qml" line="2805"/>
+ <location filename="../qml/pages/HomePage.qml" line="2764"/>
+ <location filename="../qml/pages/HomePage.qml" line="2770"/>
<source>Search clipboard history</source>
<translation>搜索剪贴板历史记录</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2825"/>
+ <location filename="../qml/pages/HomePage.qml" line="2790"/>
<source>From %1</source>
<translation>来自 %1</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2825"/>
+ <location filename="../qml/pages/HomePage.qml" line="2790"/>
<source>From phone</source>
<translation>来自手机</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2826"/>
+ <location filename="../qml/pages/HomePage.qml" line="2791"/>
<source>Sent to %1</source>
<translation>已发送到 %1</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2826"/>
+ <location filename="../qml/pages/HomePage.qml" line="2791"/>
<source>From this PC</source>
<translation>来自本机</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2832"/>
+ <location filename="../qml/pages/HomePage.qml" line="2797"/>
<source>Image</source>
<translation>图片</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2870"/>
+ <location filename="../qml/pages/HomePage.qml" line="2835"/>
<source>Pinned</source>
<translation>已固定</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2914"/>
+ <location filename="../qml/pages/HomePage.qml" line="2879"/>
<source>Open on phone</source>
<translation>在手机上打开</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2923"/>
+ <location filename="../qml/pages/HomePage.qml" line="2888"/>
<source>Send to phone</source>
<translation>发送到手机</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2931"/>
+ <location filename="../qml/pages/HomePage.qml" line="2896"/>
<source>Copy</source>
<translation>复制</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2937"/>
+ <location filename="../qml/pages/HomePage.qml" line="2902"/>
<source>Unpin</source>
<translation>取消固定</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2937"/>
+ <location filename="../qml/pages/HomePage.qml" line="2902"/>
<source>Pin</source>
<translation>固定</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="2942"/>
+ <location filename="../qml/pages/HomePage.qml" line="2907"/>
<source>Delete</source>
<translation>删除</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3230"/>
- <location filename="../qml/pages/HomePage.qml" line="3241"/>
+ <location filename="../qml/pages/HomePage.qml" line="3195"/>
+ <location filename="../qml/pages/HomePage.qml" line="3206"/>
<source>%1%</source>
<translation>%1%</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3382"/>
+ <location filename="../qml/pages/HomePage.qml" line="3347"/>
<source>LocalSend nearby · %1</source>
<translation>LocalSend 附近 · %1</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3383"/>
+ <location filename="../qml/pages/HomePage.qml" line="3348"/>
<source>LocalSend nearby</source>
<translation>LocalSend 附近</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3392"/>
+ <location filename="../qml/pages/HomePage.qml" line="3357"/>
<source>Refresh</source>
<translation>刷新</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3403"/>
+ <location filename="../qml/pages/HomePage.qml" line="3368"/>
<source>Listening for LocalSend devices on your Wi‑Fi network.</source>
<translation>正在您的 Wi‑Fi 网络上监听 LocalSend 设备。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3404"/>
+ <location filename="../qml/pages/HomePage.qml" line="3369"/>
<source>LocalSend port 53317 is busy on this PC (another LocalSend app may be running).</source>
<translation>本机的 LocalSend 端口 53317 已被占用(可能正在运行另一个 LocalSend 应用)。</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3443"/>
+ <location filename="../qml/pages/HomePage.qml" line="3408"/>
<source>Nearby device</source>
<translation>附近设备</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3499"/>
+ <location filename="../qml/pages/HomePage.qml" line="3464"/>
<source>Image preview</source>
<translation>图片预览</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3506"/>
+ <location filename="../qml/pages/HomePage.qml" line="3471"/>
<source>Close</source>
<translation>关闭</translation>
</message>
<message>
- <location filename="../qml/pages/HomePage.qml" line="3534"/>
+ <location filename="../qml/pages/HomePage.qml" line="3499"/>
<source>Open externally</source>
<translation>用外部程序打开</translation>
</message>
@@ -3073,16 +3092,21 @@
</message>
<message>
<location filename="rust_strings.h" line="71"/>
+ <source>Set up Wireless debugging in NectarLink on the phone to open its apps here.</source>
+ <translation>在手机上的 NectarLink 中设置无线调试,即可在这里打开其应用。</translation>
+ </message>
+ <message>
+ <location filename="rust_strings.h" line="72"/>
<source>The screenshot couldn&apos;t be copied to the clipboard.</source>
<translation>无法将截图复制到剪贴板。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="72"/>
+ <location filename="rust_strings.h" line="73"/>
<source>The screenshot couldn&apos;t be saved.</source>
<translation>无法保存截图。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="73"/>
+ <location filename="rust_strings.h" line="74"/>
<source>Wait for the screen to appear first.</source>
<translation>请等待屏幕先显示出来。</translation>
</message>
@@ -3319,7 +3343,7 @@
<context>
<name>Notifications</name>
<message>
- <location filename="rust_strings.h" line="74"/>
+ <location filename="rust_strings.h" line="75"/>
<source>Code copied</source>
<translation>已复制验证码</translation>
</message>
@@ -3598,17 +3622,17 @@
<context>
<name>PhoneMic</name>
<message>
- <location filename="rust_strings.h" line="75"/>
+ <location filename="rust_strings.h" line="76"/>
<source>Tap Start on %1 to use its microphone.</source>
<translation>在 %1 上轻触“开始”以使用其麦克风。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="76"/>
+ <location filename="rust_strings.h" line="77"/>
<source>The microphone is turned off for this PC on %1.</source>
<translation>%1 上已为此电脑关闭麦克风。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="77"/>
+ <location filename="rust_strings.h" line="78"/>
<source>Update NectarLink on %1 to use its microphone.</source>
<translation>请更新 %1 上的 NectarLink 以使用其麦克风。</translation>
</message>
@@ -3616,52 +3640,52 @@
<context>
<name>Photos</name>
<message>
- <location filename="rust_strings.h" line="78"/>
+ <location filename="rust_strings.h" line="79"/>
<source>Copied to clipboard.</source>
<translation>已复制到剪贴板。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="79"/>
+ <location filename="rust_strings.h" line="80"/>
<source>No recent photos found on the phone.</source>
<translation>手机上没有最近的照片。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="80"/>
+ <location filename="rust_strings.h" line="81"/>
<source>Opening latest photo…</source>
<translation>正在打开最新照片…</translation>
</message>
<message>
- <location filename="rust_strings.h" line="81"/>
+ <location filename="rust_strings.h" line="82"/>
<source>Saved %1 items to %2.</source>
<translation>已将 %1 个项目保存到 %2。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="82"/>
+ <location filename="rust_strings.h" line="83"/>
<source>Saved %1 to %2.</source>
<translation>已将 %1 保存到 %2。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="83"/>
+ <location filename="rust_strings.h" line="84"/>
<source>That photo isn&apos;t on the phone anymore.</source>
<translation>该照片已不在手机上。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="84"/>
+ <location filename="rust_strings.h" line="85"/>
<source>The phone doesn&apos;t share photos or files with this PC.</source>
<translation>手机未与此电脑共享照片或文件。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="85"/>
+ <location filename="rust_strings.h" line="86"/>
<source>The phone isn&apos;t connected right now.</source>
<translation>手机当前未连接。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="86"/>
+ <location filename="rust_strings.h" line="87"/>
<source>The photo couldn&apos;t be copied to the clipboard.</source>
<translation>无法将照片复制到剪贴板。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="87"/>
+ <location filename="rust_strings.h" line="88"/>
<source>The photo couldn&apos;t be copied. It&apos;s in Downloads\Nectarlink.</source>
<translation>无法复制照片。它在 Downloads\Nectarlink 中。</translation>
</message>
@@ -3941,32 +3965,32 @@
<context>
<name>PlayOnPhone</name>
<message>
- <location filename="rust_strings.h" line="88"/>
+ <location filename="rust_strings.h" line="89"/>
<source>Connect your phone to play on it.</source>
<translation>请连接手机后再在其上播放。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="89"/>
+ <location filename="rust_strings.h" line="90"/>
<source>Media is turned off for %1.</source>
<translation>已为 %1 关闭媒体。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="90"/>
+ <location filename="rust_strings.h" line="91"/>
<source>Opening in %1 on %2. Tap the notification there.</source>
<translation>正在 %2 上用 %1 打开。请轻触那里的通知。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="91"/>
+ <location filename="rust_strings.h" line="92"/>
<source>Sent to %1. Tap the notification there.</source>
<translation>已发送到 %1。请轻触那里的通知。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="92"/>
+ <location filename="rust_strings.h" line="93"/>
<source>Tap the notification on %1 to watch.</source>
<translation>轻触 %1 上的通知即可观看。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="93"/>
+ <location filename="rust_strings.h" line="94"/>
<source>Update NectarLink on %1 to play on it.</source>
<translation>请更新 %1 上的 NectarLink 以在其上播放。</translation>
</message>
@@ -5702,77 +5726,77 @@
<context>
<name>Timeline</name>
<message>
- <location filename="rust_strings.h" line="94"/>
+ <location filename="rust_strings.h" line="95"/>
<source>Copied link to clipboard.</source>
<translation>已将链接复制到剪贴板。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="95"/>
+ <location filename="rust_strings.h" line="96"/>
<source>Copied to clipboard.</source>
<translation>已复制到剪贴板。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="96"/>
+ <location filename="rust_strings.h" line="97"/>
<source>No phone is paired yet.</source>
<translation>尚未配对手机。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="97"/>
+ <location filename="rust_strings.h" line="98"/>
<source>Phone microphone</source>
<translation>手机麦克风</translation>
</message>
<message>
- <location filename="rust_strings.h" line="98"/>
+ <location filename="rust_strings.h" line="99"/>
<source>Phone webcam</source>
<translation>手机摄像头</translation>
</message>
<message>
- <location filename="rust_strings.h" line="99"/>
+ <location filename="rust_strings.h" line="100"/>
<source>Screen mirroring</source>
<translation>屏幕镜像</translation>
</message>
<message>
- <location filename="rust_strings.h" line="100"/>
+ <location filename="rust_strings.h" line="101"/>
<source>Sending to %1…</source>
<translation>正在发送到 %1…</translation>
</message>
<message>
- <location filename="rust_strings.h" line="101"/>
+ <location filename="rust_strings.h" line="102"/>
<source>Sent clip to %1.</source>
<translation>已将剪贴内容发送到 %1。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="102"/>
+ <location filename="rust_strings.h" line="103"/>
<source>That clip is no longer in clipboard history.</source>
<translation>该剪贴内容已不在剪贴板历史中。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="103"/>
+ <location filename="rust_strings.h" line="104"/>
<source>That entry couldn&apos;t be removed. Try again.</source>
<translation>无法删除该条目,请重试。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="104"/>
+ <location filename="rust_strings.h" line="105"/>
<source>That file was moved or deleted.</source>
<translation>该文件已被移动或删除。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="105"/>
+ <location filename="rust_strings.h" line="106"/>
<source>That isn&apos;t a web link.</source>
<translation>这不是网页链接。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="106"/>
+ <location filename="rust_strings.h" line="107"/>
<source>That photo was moved or deleted.</source>
<translation>该照片已被移动或删除。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="107"/>
+ <location filename="rust_strings.h" line="108"/>
<source>The Timeline couldn&apos;t be cleared. Try again.</source>
<translation>无法清除时间线,请重试。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="108"/>
+ <location filename="rust_strings.h" line="109"/>
<source>The photo couldn&apos;t be copied to the clipboard.</source>
<translation>无法将照片复制到剪贴板。</translation>
</message>
@@ -6064,17 +6088,17 @@
<context>
<name>Transfers</name>
<message>
- <location filename="rust_strings.h" line="109"/>
+ <location filename="rust_strings.h" line="110"/>
<source>Files are turned off for that device.</source>
<translation>已为该设备关闭文件。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="110"/>
+ <location filename="rust_strings.h" line="111"/>
<source>That&apos;s too many files to send at once.</source>
<translation>文件太多,无法一次发送。</translation>
</message>
<message>
- <location filename="rust_strings.h" line="111"/>
+ <location filename="rust_strings.h" line="112"/>
<source>There&apos;s nothing to send in there.</source>
<translation>那里没有可发送的内容。</translation>
</message>
diff --git a/desktop/app/qml/components/SwitchBar.qml b/desktop/app/qml/components/SwitchBar.qml
new file mode 100644
index 0000000..df57c43
--- /dev/null
+++ b/desktop/app/qml/components/SwitchBar.qml
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+import QtQuick
+import app.nectarlink
+
+// A full-width row with an icon, a title, an optional caption and a switch
+// (Phone as speaker, Play on phone). It fills in while on; `enabled: false`
+// greys it out until it can be used.
+Rectangle {
+ id: bar
+ property string iconPath
+ property string title
+ // Shown under the title when not empty.
+ property string caption
+ property bool checked: false
+ signal toggled(bool on)
+
+ readonly property color ink: checked
+ ? (Theme.graphite ? Theme.surface : Theme.secondaryContainerContent)
+ : Theme.surfaceContent
+
+ height: 44
+ radius: Theme.radiusMd
+ color: checked
+ ? (Theme.graphite ? Theme.surfaceContent : Theme.secondaryContainer)
+ : (Theme.graphite ? "transparent" : Theme.surfaceContainerHigh)
+ border.width: Theme.graphite || checked ? 1 : 0
+ border.color: checked ? Theme.primary : Theme.outlineVariant
+
+ Row {
+ anchors.left: parent.left
+ anchors.leftMargin: 12
+ anchors.right: barSwitch.left
+ anchors.rightMargin: 8
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 10
+ opacity: bar.enabled ? 1 : 0.38
+ Icon {
+ anchors.verticalCenter: parent.verticalCenter
+ width: 17; height: 17
+ path: bar.iconPath
+ color: bar.ink
+ }
+ Column {
+ width: parent.width - 27
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 1
+ Txt {
+ width: parent.width
+ role: "label"
+ elide: Text.ElideRight
+ color: bar.ink
+ text: bar.title
+ }
+ Txt {
+ visible: bar.caption.length > 0
+ width: parent.width
+ role: "caption"
+ elide: Text.ElideRight
+ color: bar.ink
+ opacity: 0.85
+ text: bar.caption
+ }
+ }
+ }
+ Toggle {
+ id: barSwitch
+ anchors.right: parent.right
+ anchors.rightMargin: 10
+ anchors.verticalCenter: parent.verticalCenter
+ label: bar.title
+ checked: bar.checked
+ onToggled: (on) => bar.toggled(on)
+ }
+}
diff --git a/desktop/app/qml/pages/HomePage.qml b/desktop/app/qml/pages/HomePage.qml
index e736fe8..1630fef 100644
--- a/desktop/app/qml/pages/HomePage.qml
+++ b/desktop/app/qml/pages/HomePage.qml
@@ -2007,64 +2007,29 @@ Item {
}
}
- Rectangle {
- id: pcSpeakerBar
+ SwitchBar {
width: parent.width
- height: 44
- radius: Theme.radiusMd
- color: Preferences.streamPcAudioToPhone
- ? (Theme.graphite ? Theme.surfaceContent : Theme.secondaryContainer)
- : (Theme.graphite ? "transparent" : Theme.surfaceContainerHigh)
- border.width: Theme.graphite || Preferences.streamPcAudioToPhone ? 1 : 0
- border.color: Preferences.streamPcAudioToPhone ? Theme.primary : Theme.outlineVariant
- Row {
- anchors.left: parent.left
- anchors.leftMargin: 12
- anchors.right: pcSpeakerSwitch.left
- anchors.rightMargin: 8
- anchors.verticalCenter: parent.verticalCenter
- spacing: 10
- Icon {
- anchors.verticalCenter: parent.verticalCenter
- width: 17; height: 17
- path: Icons.speaker
- color: Preferences.streamPcAudioToPhone
- ? (Theme.graphite ? Theme.surface : Theme.secondaryContainerContent)
- : Theme.surfaceContent
- }
- Column {
- width: parent.width - 27
- anchors.verticalCenter: parent.verticalCenter
- spacing: 1
- Txt {
- width: parent.width
- role: "label"
- elide: Text.ElideRight
- color: Preferences.streamPcAudioToPhone
- ? (Theme.graphite ? Theme.surface : Theme.secondaryContainerContent)
- : Theme.surfaceContent
- text: qsTr("Phone as speaker")
- }
- Txt {
- visible: Preferences.streamPcAudioToPhone
- width: parent.width
- role: "caption"
- elide: Text.ElideRight
- color: Theme.graphite ? Theme.surface : Theme.secondaryContainerContent
- opacity: 0.85
- text: qsTr("Streaming PC audio")
- }
- }
- }
- Toggle {
- id: pcSpeakerSwitch
- anchors.right: parent.right
- anchors.rightMargin: 10
- anchors.verticalCenter: parent.verticalCenter
- label: qsTr("Phone as speaker")
- checked: Preferences.streamPcAudioToPhone
- onToggled: (on) => Preferences.streamPcAudioToPhone = on
- }
+ iconPath: Icons.speaker
+ title: qsTr("Phone as speaker")
+ caption: checked ? qsTr("Streaming PC audio") : ""
+ checked: Preferences.streamPcAudioToPhone
+ onToggled: (on) => Preferences.streamPcAudioToPhone = on
+ }
+
+ // Play on phone: the video playing on this PC, on the phone.
+ // Greyed out until a video plays.
+ SwitchBar {
+ readonly property string watch: MediaList.playOnPhoneState
+ width: parent.width
+ iconPath: Icons.video
+ title: qsTr("Play on phone")
+ enabled: watch !== "off" || MediaList.canPlayOnPhone
+ checked: watch !== "off"
+ caption: watch === "watching" ? qsTr("Watching on %1").arg(MediaList.playOnPhoneName)
+ : watch === "asking" ? qsTr("Tap the notification on %1").arg(MediaList.playOnPhoneName)
+ : MediaList.canPlayOnPhone ? ""
+ : qsTr("Play a video on this PC first")
+ onToggled: (on) => MediaList.setPlayOnPhone(on)
}
LockChip {
diff --git a/desktop/app/src/bridge/media.rs b/desktop/app/src/bridge/media.rs
index a4abaac..bae92db 100644
--- a/desktop/app/src/bridge/media.rs
+++ b/desktop/app/src/bridge/media.rs
@@ -44,6 +44,10 @@ pub mod qobject {
#[qproperty(QString, active_colors, cxx_name = "activeColors")]
/// The phone Play on phone plays on (its name), or "" when none is online.
#[qproperty(QString, play_on_phone_name, cxx_name = "playOnPhoneName")]
+ /// Whether a video plays on this PC that Play on phone can take.
+ #[qproperty(bool, can_play_on_phone, cxx_name = "canPlayOnPhone")]
+ /// Play on phone: "off", "asking" (the phone's notification is up) or "watching".
+ #[qproperty(QString, play_on_phone_state, cxx_name = "playOnPhoneState")]
type MediaList = super::MediaListRust;
}
@@ -101,6 +105,10 @@ pub mod qobject {
#[qinvokable]
#[cxx_name = "isPlaying"]
fn is_playing(self: &MediaList, row: i32) -> bool;
+ /// The Play on phone toggle.
+ #[qinvokable]
+ #[cxx_name = "setPlayOnPhone"]
+ fn set_play_on_phone(self: &MediaList, on: bool);
}
impl cxx_qt::Threading for MediaList {}
@@ -114,6 +122,8 @@ pub struct MediaListRust {
active_art: QString,
active_colors: QString,
play_on_phone_name: QString,
+ can_play_on_phone: bool,
+ play_on_phone_state: QString,
rows: Vec<PlayerView>,
}
@@ -186,7 +196,7 @@ impl cxx_qt::Initialize for qobject::MediaList {
fn initialize(self: Pin<&mut Self>) {
super::subscribe(
self.qt_thread(),
- Changes::MEDIA | Changes::DEVICES | Changes::CAPABILITIES,
+ Changes::MEDIA | Changes::DEVICES | Changes::CAPABILITIES | Changes::REMOTE,
Self::refresh,
);
}
@@ -243,10 +253,22 @@ impl qobject::MediaList {
if *self.play_on_phone_name() != phone {
self.as_mut().set_play_on_phone_name(phone);
}
+ let can = !self.play_on_phone_name().is_empty() && crate::play_on_phone::watchable().is_some();
+ if self.can_play_on_phone != can {
+ self.as_mut().set_can_play_on_phone(can);
+ }
+ let watch = QString::from(crate::play_on_phone::state());
+ if *self.play_on_phone_state() != watch {
+ self.as_mut().set_play_on_phone_state(watch);
+ }
let revision = self.revision.wrapping_add(1);
self.set_revision(revision);
}
+ pub fn set_play_on_phone(&self, on: bool) {
+ crate::play_on_phone::set_on(on);
+ }
+
pub fn first_for(&self, device: &QString) -> i32 {
let device = String::from(device);
let matches_dev = |r: &PlayerView| {
diff --git a/desktop/app/src/pc_mirror.rs b/desktop/app/src/pc_mirror.rs
index 8787768..4e729ce 100644
--- a/desktop/app/src/pc_mirror.rs
+++ b/desktop/app/src/pc_mirror.rs
@@ -89,6 +89,20 @@ pub fn is_active() -> bool {
active_peer().is_some()
}
+/// Whether a phone watches one of this PC's players (Play on phone).
+pub fn is_watching() -> bool {
+ ACTIVE.lock().unwrap_or_else(|e| e.into_inner()).as_ref().is_some_and(|s| s.watching)
+}
+
+/// Stops a phone watching one of this PC's players; screen sharing goes on.
+pub fn stop_watching() {
+ let peer =
+ ACTIVE.lock().unwrap_or_else(|e| e.into_inner()).as_ref().filter(|s| s.watching).map(|s| s.peer);
+ if let Some(peer) = peer {
+ stop_for(&peer);
+ }
+}
+
/// Starts or replaces the active PC-to-phone screen mirror stream for `peer`.
pub fn start(peer: DeviceId, options: MirrorStart) {
stop_all();
@@ -173,8 +187,7 @@ pub fn handle_input(peer: &DeviceId, session: u32, input: MirrorInput) {
if session != nectarlink_core::MIRROR_SCREEN {
return;
}
- let watching = ACTIVE.lock().unwrap_or_else(|e| e.into_inner()).as_ref().is_some_and(|s| s.watching);
- if active_peer() != Some(*peer) || watching {
+ if active_peer() != Some(*peer) || is_watching() {
return;
}
let remote_input_on = core_host::node()
diff --git a/desktop/app/src/play_on_phone.rs b/desktop/app/src/play_on_phone.rs
index f914312..bc22235 100644
--- a/desktop/app/src/play_on_phone.rs
+++ b/desktop/app/src/play_on_phone.rs
@@ -12,7 +12,7 @@ use std::{
Arc, Mutex,
atomic::{AtomicBool, Ordering},
},
- time::Duration,
+ time::{Duration, Instant},
};
use nectarlink_core::{DeviceId, Error, FeatureState, LinkState, MediaAction, PlayOnPhone};
@@ -40,6 +40,87 @@ pub fn phone() -> Option<(DeviceId, String)> {
})
}
+/// Apps (by player ID or name) that play music, never a video worth
+/// watching on a phone, unless they say otherwise.
+const MUSIC_APPS: &[&str] = &[
+ "spotify",
+ "applemusic",
+ "itunes",
+ "zunemusic",
+ "foobar2000",
+ "musicbee",
+ "aimp",
+ "winamp",
+ "tidal",
+ "deezer",
+ "amazonmusic",
+ "youtube music",
+ "soundcloud",
+];
+
+/// Whether a player looks like it plays a video: it says so, or it is
+/// anything but a music app (browsers say "music" for every video).
+pub(crate) fn plays_video(id: &str, app: &str, says_video: bool) -> bool {
+ if says_video {
+ return true;
+ }
+ let (id, app) = (id.to_ascii_lowercase(), app.to_ascii_lowercase());
+ !MUSIC_APPS.iter().any(|m| id.contains(m) || app.contains(m))
+}
+
+/// The player of this PC's to offer for Play on phone: the first one playing
+/// a video.
+pub fn watchable() -> Option<String> {
+ crate::media::local_views()
+ .into_iter()
+ .map(|v| v.player)
+ .find(|p| p.playing && plays_video(&p.id, &p.app, crate::win::media_sessions::says_video(&p.id)))
+ .map(|p| p.id)
+}
+
+/// When a phone was last asked to watch (its notification is up).
+static ASKED: Mutex<Option<Instant>> = Mutex::new(None);
+/// How long a phone has to accept before the toggle gives up waiting.
+const ASK_FOR: Duration = Duration::from_secs(60);
+
+/// Where Play on phone is: `"off"`, `"asking"` (the phone's notification
+/// is up) or `"watching"`.
+pub fn state() -> &'static str {
+ if crate::pc_mirror::is_watching() {
+ *ASKED.lock().unwrap_or_else(|e| e.into_inner()) = None;
+ return "watching";
+ }
+ match *ASKED.lock().unwrap_or_else(|e| e.into_inner()) {
+ Some(at) if at.elapsed() < ASK_FOR => "asking",
+ _ => "off",
+ }
+}
+
+fn asked() {
+ *ASKED.lock().unwrap_or_else(|e| e.into_inner()) = Some(Instant::now());
+ core_host::host().hub.changed(crate::state::Changes::MEDIA);
+ // The toggle stops waiting when the phone doesn't answer.
+ core_host::spawn(async {
+ tokio::time::sleep(ASK_FOR).await;
+ core_host::host().hub.changed(crate::state::Changes::MEDIA);
+ });
+}
+
+/// The Play on phone toggle: on plays the video playing now on the phone;
+/// off stops the phone watching (or waiting to).
+pub fn set_on(on: bool) {
+ if on {
+ match watchable() {
+ Some(player) => play(player),
+ None => core_host::host().hub.changed(crate::state::Changes::MEDIA),
+ }
+ return;
+ }
+ *ASKED.lock().unwrap_or_else(|e| e.into_inner()) = None;
+ crate::pc_mirror::stop_watching();
+ core_host::host().hub.changed(crate::state::Changes::MEDIA);
+}
+
/// What this PC's `player` plays: its title, and where it is, in seconds.
fn now_playing(player: &str) -> (String, Option<u32>) {
let views = crate::media::local_views();
@@ -89,6 +170,7 @@ pub fn play(player: String) {
let shown = (!title.is_empty()).then_some(title);
match node.offer_watch(phone, player.clone(), shown).await {
Ok(()) => {
+ asked();
show_message(tr!("PlayOnPhone", "Tap the notification on %1 to watch.", name))
}
// A phone that can't watch yet: the page opens there instead.
@@ -226,3 +308,19 @@ impl Drop for Watched {
self.stop.store(true, Ordering::Relaxed);
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::plays_video;
+
+ #[test]
+ fn music_apps_are_not_offered_unless_they_say_video() {
+ assert!(plays_video("chrome", "YouTube", false), "a browser's video says music");
+ assert!(plays_video("F0DC299D809B9700", "Zen", false));
+ assert!(plays_video(r"C:/Program Files/VideoLAN/VLC/vlc.exe", "vlc", false));
+ assert!(!plays_video("Spotify.exe", "Spotify", false));
+ assert!(!plays_video("chrome", "YouTube Music", false), "named by its site");
+ assert!(!plays_video("Microsoft.ZuneMusic_8wekyb3d8bbwe!Microsoft.ZuneMusic", "Media Player", false));
+ assert!(plays_video("Microsoft.ZuneMusic_8wekyb3d8bbwe!Microsoft.ZuneMusic", "Media Player", true));
+ }
+}
diff --git a/desktop/app/src/win/media_sessions.rs b/desktop/app/src/win/media_sessions.rs
index 7206ede..6504273 100644
--- a/desktop/app/src/win/media_sessions.rs
+++ b/desktop/app/src/win/media_sessions.rs
@@ -20,6 +20,7 @@ use windows::{
GlobalSystemMediaTransportControlsSession, GlobalSystemMediaTransportControlsSessionManager,
GlobalSystemMediaTransportControlsSessionPlaybackStatus,
},
+ Media::MediaPlaybackType,
Storage::Streams::DataReader,
Win32::System::Com::{COINIT_MULTITHREADED, CoInitializeEx},
core::HSTRING,
@@ -38,6 +39,14 @@ const WINDOWS_TO_UNIX_SECS: i64 = 11_644_473_600;
type OnChange = Box<dyn Fn(Vec<MediaPlayer>) + Send + Sync>;
static MANAGER: OnceLock<GlobalSystemMediaTransportControlsSessionManager> = OnceLock::new();
+/// Players that say they play a video (most browsers say "music" for
+/// everything, so this is a hint, not the whole answer).
+static VIDEO: Mutex<Option<HashSet<String>>> = Mutex::new(None);
+
+/// Whether this PC's player `id` says it plays a video.
+pub fn says_video(id: &str) -> bool {
+ VIDEO.lock().unwrap_or_else(|e| e.into_inner()).as_ref().is_some_and(|v| v.contains(id))
+}
/// Watches this PC's media; `on_change` gets every player after each
/// change (on the watcher's thread).
@@ -226,6 +235,17 @@ fn player(
if title.is_none() {
return Ok(None);
}
+ let video =
+ properties.PlaybackType().and_then(|t| t.Value()).is_ok_and(|t| t == MediaPlaybackType::Video);
+ {
+ let mut guard = VIDEO.lock().unwrap_or_else(|e| e.into_inner());
+ let set = guard.get_or_insert_default();
+ if video {
+ set.insert(id.clone());
+ } else {
+ set.remove(&id);
+ }
+ }
let info = session.GetPlaybackInfo()?;
let playing = info.PlaybackStatus()? == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing;
let controls = info.Controls()?;
diff --git a/desktop/app/tests/qml/tst_switchbar.qml b/desktop/app/tests/qml/tst_switchbar.qml
new file mode 100644
index 0000000..190ad46
--- /dev/null
+++ b/desktop/app/tests/qml/tst_switchbar.qml
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+import QtQuick
+import QtTest
+import app.nectarlink
+
+// A SwitchBar reports the user's choice, shows its caption only when there
+// is one, and takes no input while greyed out.
+Item {
+ id: root
+ width: 360
+ height: 60
+
+ SwitchBar {
+ id: bar
+ x: 10
+ y: 8
+ width: 320
+ iconPath: Icons.video
+ title: "Play on phone"
+ }
+
+ SignalSpy {
+ id: toggled
+ target: bar
+ signalName: "toggled"
+ }
+
+ TestCase {
+ name: "SwitchBar"
+ when: windowShown
+
+ function init() {
+ bar.enabled = true
+ bar.checked = false
+ bar.caption = ""
+ toggled.clear()
+ }
+
+ function test_a_click_on_the_switch_reports_on() {
+ mouseClick(bar, bar.width - 30, bar.height / 2)
+ compare(toggled.count, 1)
+ compare(toggled.signalArguments[0][0], true)
+ verify(!bar.checked, "the owner decides")
+ }
+
+ function test_a_greyed_out_bar_takes_no_click() {
+ bar.enabled = false
+ mouseClick(bar, bar.width - 30, bar.height / 2)
+ compare(toggled.count, 0)
+ }
+
+ function test_the_caption_shows_only_when_set() {
+ bar.caption = "Watching on Pixel"
+ verify(hasText(bar, "Watching on Pixel"))
+ bar.caption = ""
+ verify(!hasText(bar, "Watching on Pixel"))
+ }
+
+ // Whether a visible text item under `item` shows `text`.
+ function hasText(item, text) {
+ for (let i = 0; i < item.children.length; i++) {
+ const child = item.children[i]
+ if (child.visible && child.text === text)
+ return true
+ if (child.visible && hasText(child, text))
+ return true
+ }
+ return false
+ }
+ }
+}