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/),
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

View File

@@ -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<IpcSocket>,
/// The object to render to the terminal.
cursive: CursiveRunner<Cursive>,
}
@@ -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);