Skip to content

Commit

Permalink
fix: crash on Termux due to missing runtime directory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ThomasFrans committed Jan 2, 2024
1 parent 2a44323 commit 91fa165
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 91fa165

Please sign in to comment.