Skip to content

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

PC files on the phone: say why a folder can't be listed

Beef7bcb7318eb6
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt b/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
index 84ecbf2..bc15326 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
@@ -2125,14 +2125,27 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
fun listPcFiles(
deviceId: String,
path: String,
- onResult: (List<RemoteStorageEntry>) -> Unit,
+ onResult: (PcFolder) -> Unit,
) {
scope.launch(Dispatchers.IO) {
startJob?.join()
- val entries = runCatching { node?.listRemoteStorage(deviceId, path).orEmpty() }
- .getOrDefault(emptyList())
+ val folder = try {
+ PcFolder(node?.listRemoteStorage(deviceId, path).orEmpty())
+ } catch (e: NectarlinkException) {
+ Log.i(TAG, "can't list a PC's folder: $e")
+ PcFolder(
+ emptyList(),
+ when (e) {
+ is NectarlinkException.Denied -> R.string.pc_files_not_shared
+ is NectarlinkException.Offline, is NectarlinkException.NotPaired -> R.string.pc_files_offline
+ is NectarlinkException.Unsupported -> R.string.pc_files_update
+ is NectarlinkException.NotFound -> R.string.pc_files_not_found
+ else -> R.string.pc_files_error
+ },
+ )
+ }
withContext(Dispatchers.Main) {
- onResult(entries)
+ onResult(folder)
}
}
}
@@ -2240,3 +2253,9 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
val PHOTO_CAPABILITIES = listOf("photos.read")
}
}
+
+/** A folder on a PC: its files, or why they can't be listed (a string resource). */
+data class PcFolder(
+ val entries: List<RemoteStorageEntry>,
+ @androidx.annotation.StringRes val problem: Int? = null,
+)
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt
index d0f3e5b..9cbbb4e 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt
@@ -105,6 +105,7 @@ import app.nectarlink.android.contacts.PhoneContacts
import app.nectarlink.android.core.BackgroundAccess
import app.nectarlink.android.core.CoreState
import app.nectarlink.android.core.Device
+import app.nectarlink.android.core.PcFolder
import app.nectarlink.android.core.LocalNetwork
import app.nectarlink.android.core.WakeState
import app.nectarlink.android.core.isFinished
@@ -211,8 +212,8 @@ fun HomeScreen(
onResendTimelineEntry: (entry: TimelineEntry) -> Unit = {},
onSetPcAudio: (pcId: String, volume: Int?, muted: Boolean?) -> Unit = { _, _, _ -> },
onStopKeyboardFromPc: (pcId: String) -> Unit = {},
- onListPcFiles: (pcId: String, path: String, onResult: (List<RemoteStorageEntry>) -> Unit) -> Unit = { _, _, onResult ->
- onResult(emptyList())
+ onListPcFiles: (pcId: String, path: String, onResult: (PcFolder) -> Unit) -> Unit = { _, _, onResult ->
+ onResult(PcFolder(emptyList()))
},
onDownloadPcFile: (pcId: String, remotePath: String, fileName: String, onSaved: (Uri?) -> Unit) -> Unit = { _, _, _, onSaved ->
onSaved(null)
@@ -3246,7 +3247,7 @@ private fun parentRemotePath(path: String): String {
@Composable
private fun PcFilesSheet(
device: Device,
- onListFiles: (path: String, onResult: (List<RemoteStorageEntry>) -> Unit) -> Unit,
+ onListFiles: (path: String, onResult: (PcFolder) -> Unit) -> Unit,
onDownloadFile: (remotePath: String, fileName: String, onSaved: (Uri?) -> Unit) -> Unit,
onDismiss: () -> Unit,
) {
@@ -3260,11 +3261,13 @@ private fun PcFilesSheet(
var loading by remember(device.id) { mutableStateOf(false) }
var downloadingPath by remember(device.id) { mutableStateOf<String?>(null) }
var refreshTick by remember(device.id) { mutableStateOf(0) }
+ var problem by remember(device.id) { mutableStateOf<Int?>(null) }
LaunchedEffect(device.id, currentPath, refreshTick) {
loading = true
- onListFiles(currentPath) { fetched ->
- entries = fetched.sortedWith(
+ onListFiles(currentPath) { folder ->
+ problem = folder.problem
+ entries = folder.entries.sortedWith(
compareBy<RemoteStorageEntry> { !it.isDirectoryEntry() }
.thenBy(String.CASE_INSENSITIVE_ORDER) { it.name },
)
@@ -3353,6 +3356,14 @@ private fun PcFilesSheet(
}
when {
+ problem != null && !loading -> {
+ Text(
+ stringResource(problem ?: R.string.pc_files_error, device.name),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier.padding(vertical = 16.dp),
+ )
+ }
loading && entries.isEmpty() -> {
Text(
stringResource(R.string.pc_files_loading),
diff --git a/android/app/src/main/res/values-zh-rCN/strings.xml b/android/app/src/main/res/values-zh-rCN/strings.xml
index 9d1c3d8..ccc5113 100644
--- a/android/app/src/main/res/values-zh-rCN/strings.xml
+++ b/android/app/src/main/res/values-zh-rCN/strings.xml
@@ -632,6 +632,11 @@
<string name="pc_files_downloading">正在下载 %1$s…</string>
<string name="pc_files_saved">已将 %1$s 保存到“下载”</string>
<string name="pc_files_failed">无法下载 %1$s</string>
+ <string name="pc_files_not_shared">在 %1$s 上的 NectarLink 设置中打开“口袋里的电脑”。</string>
+ <string name="pc_files_offline">%1$s 未连接。</string>
+ <string name="pc_files_update">请更新 %1$s 上的 NectarLink 以浏览其文件。</string>
+ <string name="pc_files_not_found">此文件夹已不在 %1$s 上。</string>
+ <string name="pc_files_error">无法列出 %1$s 上的此文件夹,请重试。</string>
<string name="pc_files_folder_downloads">下载</string>
<string name="pc_files_folder_documents">文档</string>
<string name="pc_files_folder_desktop">桌面</string>
@@ -950,9 +955,9 @@
<string name="guide_pc_files_summary">在手机上浏览电脑共享的文件夹,并将文件下载到下载文件夹。</string>
<string name="guide_pc_files_where">首页 › 已配对电脑卡片 › 浏览电脑文件</string>
<string name="guide_pc_files_needs">已配对且在线的电脑,并已启用存储共享</string>
- <string name="guide_pc_files_need_1">已配对且在线的电脑,并已为此手机启用存储访问。</string>
+ <string name="guide_pc_files_need_1">已配对且在线、并共享其文件夹(口袋里的电脑)的电脑。</string>
<string name="guide_pc_files_phone_1">在首页的已配对电脑卡片上点按浏览电脑文件,点按任意文件即可下载。</string>
- <string name="guide_pc_files_pc_1">在电脑上的 NectarLink 中允许此手机访问存储。</string>
+ <string name="guide_pc_files_pc_1">在电脑上的 NectarLink 设置中打开“口袋里的电脑”。</string>
<string name="guide_pc_files_opt_1">浏览电脑文件面板:浏览电脑文件夹并将文件下载到下载文件夹。</string>
<string name="guide_pc_files_privacy">下载的文件保存在手机本地的下载文件夹中。</string>
<string name="guide_pc_files_limits">需要已配对电脑在线。</string>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 14febd5..fc1f6a0 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -688,6 +688,11 @@
<string name="pc_files_downloading">Downloading %1$s…</string>
<string name="pc_files_saved">Saved %1$s to Downloads</string>
<string name="pc_files_failed">Couldn’t download %1$s</string>
+ <string name="pc_files_not_shared">Turn on “Your PC in your pocket” in NectarLink’s Settings on %1$s.</string>
+ <string name="pc_files_offline">%1$s isn’t connected.</string>
+ <string name="pc_files_update">Update NectarLink on %1$s to browse its files.</string>
+ <string name="pc_files_not_found">This folder isn’t on %1$s anymore.</string>
+ <string name="pc_files_error">Couldn’t list this folder on %1$s. Try again.</string>
<string name="pc_files_folder_downloads">Downloads</string>
<string name="pc_files_folder_documents">Documents</string>
<string name="pc_files_folder_desktop">Desktop</string>
@@ -1054,9 +1059,9 @@
<string name="guide_pc_files_summary">Browse folders shared by your PC from your phone and download files to Downloads.</string>
<string name="guide_pc_files_where">Home › Paired PC card › Browse PC files</string>
<string name="guide_pc_files_needs">Online paired PC with storage sharing enabled</string>
- <string name="guide_pc_files_need_1">Online paired PC with storage access enabled for this phone.</string>
+ <string name="guide_pc_files_need_1">Online paired PC that shares its folders (Your PC in your pocket).</string>
<string name="guide_pc_files_phone_1">On Home, tap Browse PC files on your paired PC card and tap any file to download.</string>
- <string name="guide_pc_files_pc_1">Allow storage access for this phone in NectarLink on your PC.</string>
+ <string name="guide_pc_files_pc_1">Turn on Your PC in your pocket in NectarLink’s Settings on your PC.</string>
<string name="guide_pc_files_opt_1">Browse PC files sheet: Navigate PC folders and download files into Downloads.</string>
<string name="guide_pc_files_privacy">Downloaded files save locally in your phone Downloads folder.</string>
<string name="guide_pc_files_limits">Requires the paired PC to be online.</string>
diff --git a/core/nectarlink-ffi/src/lib.rs b/core/nectarlink-ffi/src/lib.rs
index 4e61d6a..1879829 100644
--- a/core/nectarlink-ffi/src/lib.rs
+++ b/core/nectarlink-ffi/src/lib.rs
@@ -4163,16 +4163,18 @@ impl NectarlinkNode {
}
/// Lists entries in a directory on a connected paired device (`storage.list`).
- pub fn list_remote_storage(&self, peer: String, path: String) -> Vec<RemoteStorageEntry> {
- let Ok(peer_id) = parse_id(&peer) else {
- return Vec::new();
- };
+ /// `Denied` from a PC: it doesn't share its folders.
+ pub fn list_remote_storage(
+ &self,
+ peer: String,
+ path: String,
+ ) -> Result<Vec<RemoteStorageEntry>, NectarlinkError> {
+ let peer_id = parse_id(&peer)?;
let node = self.node.clone();
let req_path = path.clone();
- let entries =
- self.block_on_rt(async move { node.list_storage(&peer_id, &req_path).await }).unwrap_or_default();
+ let entries = self.block_on_rt(async move { node.list_storage(&peer_id, &req_path).await })?;
let prefix = path.trim_matches('/');
- entries
+ Ok(entries
.into_iter()
.map(|e| RemoteStorageEntry {
path: if prefix.is_empty() { e.name.clone() } else { format!("{prefix}/{}", e.name) },
@@ -4181,7 +4183,7 @@ impl NectarlinkNode {
size: e.size,
modified: e.modified,
})
- .collect()
+ .collect())
}
/// Downloads a remote file from a connected paired device (`storage.read`) in