fix(linux): load peers when the app dir is unset (#16698)

Recent sessions and Favorites load only when `APP_DIR` is non-empty. That
precondition belongs to mobile alone: `Config::path` resolves through `APP_DIR`
on Android and iOS, so reading peers before it is set would look in the wrong
place there, but on desktop the peer path never consults it.

On Linux the Flutter side fills `APP_DIR` from
`getApplicationDocumentsDirectory()`, which shells out to `xdg-user-dir`. When
that executable is absent, as in a minimal Debian install or a container, the
call throws, the exception is only `debugPrint`ed, and `APP_DIR` stays empty.
All three loaders then skip their work, so both lists stay empty for good while
`~/.config/rustdesk/peers/*.toml` sit there unread and nothing in the log says
why. Windows and macOS carry the same trap, merely with a lookup that is far
less likely to fail.

Move the predicate into one helper that applies it only where the path actually
depends on it. Mobile keeps the existing check; everywhere else the peers load.

Refs #16622
This commit is contained in:
Minh Nguyen authored and GitHub committed 2026-10-26 15:45:14 +08:00
1 parent f96a44a019
commit 182356ee8b
1 file changed
+14 -3
+14 -3
View File
@@ -1454,6 +1454,17 @@ pub fn main_peer_exists(id: String) -> bool {
peer_exists(&id)
}
// `Config::path` resolves through `APP_DIR` only on mobile, where loading peers before it is set
// would read the wrong place. Elsewhere the peer path never consults it, so an unset `APP_DIR`
// must not stop the peers from loading.
fn peer_config_path_ready() -> bool {
if cfg!(any(target_os = "android", target_os = "ios")) {
!config::APP_DIR.read().unwrap().is_empty()
} else {
true
}
}
fn load_recent_peers(
vec_id_modified_time_path: &Vec<(String, SystemTime, std::path::PathBuf)>,
to_end: bool,
@@ -1485,7 +1496,7 @@ pub fn main_load_recent_peers() {
);
};
if !config::APP_DIR.read().unwrap().is_empty() {
if peer_config_path_ready() {
let vec_id_modified_time_path = PeerConfig::get_vec_id_modified_time_path(&None);
if vec_id_modified_time_path.is_empty() {
push_to_flutter("".to_owned(), None);
@@ -1533,7 +1544,7 @@ pub fn main_load_recent_peers_for_ab(filter: String) -> String {
} else {
Some(id_filters)
};
if !config::APP_DIR.read().unwrap().is_empty() {
if peer_config_path_ready() {
let peers: Vec<HashMap<&str, String>> = PeerConfig::peers(id_filters)
.drain(..)
.map(|(id, _, p)| peer_to_map(id, p))
@@ -1551,7 +1562,7 @@ pub fn main_load_fav_peers() {
serde_json::ser::to_string(&data).unwrap_or("".to_owned()),
);
};
if !config::APP_DIR.read().unwrap().is_empty() {
if peer_config_path_ready() {
let favs = get_fav();
let mut recent = PeerConfig::peers(Some(favs.clone()));
let mut lan = config::LanPeers::load()