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.
This commit is contained in:
Thomas Frans
2024-01-02 21:27:13 +01:00
committed by Henrik Friedrichsen
parent 2a44323d59
commit 0eee40e877
2 changed files with 23 additions and 10 deletions

View File

@@ -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/), 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). 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 ## [1.0.0] - 2023-12-16
### Added ### Added

View File

@@ -72,7 +72,7 @@ pub struct Application {
mpris_manager: MprisManager, mpris_manager: MprisManager,
/// An IPC implementation using a Unix domain socket, used to control and inspect ncspot. /// An IPC implementation using a Unix domain socket, used to control and inspect ncspot.
#[cfg(unix)] #[cfg(unix)]
ipc: IpcSocket, ipc: Option<IpcSocket>,
/// The object to render to the terminal. /// The object to render to the terminal.
cursive: CursiveRunner<Cursive>, cursive: CursiveRunner<Cursive>,
} }
@@ -138,14 +138,19 @@ impl Application {
); );
#[cfg(unix)] #[cfg(unix)]
let ipc = ipc::IpcSocket::new( let ipc = if let Ok(runtime_directory) = utils::create_runtime_directory() {
ASYNC_RUNTIME.get().unwrap().handle(), Some(
utils::create_runtime_directory() ipc::IpcSocket::new(
.unwrap() ASYNC_RUNTIME.get().unwrap().handle(),
.join("ncspot.sock"), runtime_directory.join("ncspot.sock"),
event_manager.clone(), event_manager.clone(),
) )
.map_err(|e| e.to_string())?; .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( let mut cmd_manager = CommandManager::new(
spotify.clone(), spotify.clone(),
@@ -236,7 +241,9 @@ impl Application {
self.mpris_manager.update(); self.mpris_manager.update();
#[cfg(unix)] #[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 { if state == PlayerEvent::FinishedTrack {
self.queue.next(false); self.queue.next(false);