From 0eee40e8778480142f781fdcc0b1b146fa7597e1 Mon Sep 17 00:00:00 2001 From: Thomas Frans Date: Tue, 2 Jan 2024 21:27:13 +0100 Subject: [PATCH] fix: crash on Termux due to missing runtime directory Instead of crashing on Termux, no IPC socket is created. This is a temporary solution until a suitable runtime directory for the Termux platform can be found. --- CHANGELOG.md | 6 ++++++ src/application.rs | 27 +++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54d94e0..1045f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Crash on Android (Termux) due to unknown user runtime directory + ## [1.0.0] - 2023-12-16 ### Added diff --git a/src/application.rs b/src/application.rs index 872d7f7..692281b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -72,7 +72,7 @@ pub struct Application { mpris_manager: MprisManager, /// An IPC implementation using a Unix domain socket, used to control and inspect ncspot. #[cfg(unix)] - ipc: IpcSocket, + ipc: Option, /// The object to render to the terminal. cursive: CursiveRunner, } @@ -138,14 +138,19 @@ impl Application { ); #[cfg(unix)] - let ipc = ipc::IpcSocket::new( - ASYNC_RUNTIME.get().unwrap().handle(), - utils::create_runtime_directory() - .unwrap() - .join("ncspot.sock"), - event_manager.clone(), - ) - .map_err(|e| e.to_string())?; + let ipc = if let Ok(runtime_directory) = utils::create_runtime_directory() { + Some( + ipc::IpcSocket::new( + ASYNC_RUNTIME.get().unwrap().handle(), + runtime_directory.join("ncspot.sock"), + event_manager.clone(), + ) + .map_err(|e| e.to_string())?, + ) + } else { + error!("failed to create IPC socket: no suitable user runtime directory found"); + None + }; let mut cmd_manager = CommandManager::new( spotify.clone(), @@ -236,7 +241,9 @@ impl Application { self.mpris_manager.update(); #[cfg(unix)] - self.ipc.publish(&state, self.queue.get_current()); + if let Some(ref ipc) = self.ipc { + ipc.publish(&state, self.queue.get_current()); + } if state == PlayerEvent::FinishedTrack { self.queue.next(false);