Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert usage of caffeinate on OSX #4407

Merged
merged 2 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions core/src/main/java/bisq/core/app/AvoidStandbyModeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;

/**
* Prevents that Bisq gets hibernated from the OS. On OSX there is a tool called caffeinate but it seems it does not
* provide the behaviour we need, thus we use the trick to play a almost silent sound file in a loop. This keeps the
* application active even if the OS has moved to hibernate. Hibernating Bisq would cause network degradations and other
* resource limitations which would lead to offers not published or if a taker takes an offer that the trade process is
* at risk to fail due too slow response time.
*/
@Slf4j
@Singleton
public class AvoidStandbyModeService {
Expand Down Expand Up @@ -88,7 +95,7 @@ public void init() {

private void start() {
isStopped = false;
if (Utilities.isLinux() || Utilities.isOSX()) {
if (Utilities.isLinux()) {
startInhibitor();
} else {
new Thread(this::playSilentAudioFile, "AvoidStandbyModeService-thread").start();
Expand Down Expand Up @@ -125,7 +132,6 @@ private void startInhibitor() {

private void stopInhibitor() {
try {
// Cannot toggle off osx caffeinate, but it will shutdown with bisq.
if (Utilities.isLinux()) {
if (!isStopped) {
Objects.requireNonNull(stopLinuxInhibitorCountdownLatch).await();
Expand Down Expand Up @@ -167,7 +173,9 @@ private void playSilentAudioFile() {

private File getSoundFile() throws IOException, ResourceNotFoundException {
File soundFile = new File(config.appDataDir, "prevent-app-nap-silent-sound.aiff");
if (!soundFile.exists()) {
// We replaced the old file which was 42 MB with a smaller file of 0.8 MB. To enforce replacement we check for
// the size...
if (!soundFile.exists() || soundFile.length() > 42000000) {
FileUtil.resourceToFile("prevent-app-nap-silent-sound.aiff", soundFile);
}
return soundFile;
Expand Down Expand Up @@ -196,7 +204,7 @@ private Optional<String[]> inhibitCommand() {
? new String[]{cmd, "--app-id", "Bisq", "--inhibit", "suspend", "--reason", "Avoid Standby", "--inhibit-only"}
: new String[]{cmd, "--who", "Bisq", "--what", "sleep", "--why", "Avoid Standby", "--mode", "block", "tail", "-f", "/dev/null"};
} else {
params = Utilities.isOSX() ? new String[]{cmd, "-w", "" + ProcessHandle.current().pid()} : null;
params = null;
}
} else {
params = null; // fall back to silent audio file player
Expand Down Expand Up @@ -235,15 +243,11 @@ private Optional<ProcessHandle> runningInhibitorProcess() {
new ArrayList<>() {{
add(gnomeSessionInhibitPathSpec.get()); // On linux, preferred inhibitor is gnome-session-inhibit,
add(systemdInhibitPathSpec.get()); // then fall back to systemd-inhibit if it is installed.
add(caffeinatePathSec.get()); // On OSX, caffeinate should be installed.
}};

private final Supplier<Optional<String>> gnomeSessionInhibitPathSpec = () ->
cmdPath.apply(new String[]{"/usr/bin/gnome-session-inhibit", "/bin/gnome-session-inhibit"});

private final Supplier<Optional<String>> systemdInhibitPathSpec = () ->
cmdPath.apply(new String[]{"/usr/bin/systemd-inhibit", "/bin/systemd-inhibit"});

private final Supplier<Optional<String>> caffeinatePathSec = () ->
cmdPath.apply(new String[]{"/usr/bin/caffeinate"});
}
Binary file modified core/src/main/resources/prevent-app-nap-silent-sound.aiff
Binary file not shown.