Skip to content

Commit

Permalink
Merge pull request #619 from HenrikJannsen/extract_electrum_binary_on…
Browse files Browse the repository at this point in the history
…ly_if_needed

Extract electrum binary only if needed
  • Loading branch information
alvasw authored Jan 1, 2023
2 parents 009508e + a97844a commit 42ff4aa
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.chat.ChatService;
import bisq.common.observable.Observable;
import bisq.common.threading.ExecutorFactory;
import bisq.common.util.CompletableFutureUtils;
import bisq.identity.IdentityService;
import bisq.network.NetworkService;
import bisq.network.NetworkServiceConfig;
Expand Down Expand Up @@ -56,11 +57,12 @@ public class DefaultApplicationService extends ApplicationService {
public static final ExecutorService DISPATCHER = ExecutorFactory.newSingleThreadExecutor("DefaultApplicationService.dispatcher");

public enum State {
NEW,
START_NETWORK,
NETWORK_STARTED,
INITIALIZE_COMPLETED,
INITIALIZE_FAILED
INITIALIZE_APP,
INITIALIZE_NETWORK,
INITIALIZE_WALLET,
INITIALIZE_SERVICES,
APP_INITIALIZED,
FAILED
}

private final SecurityService securityService;
Expand All @@ -76,7 +78,7 @@ public enum State {
private final ProtocolService protocolService;
private final SupportService supportService;

private final Observable<State> state = new Observable<>(State.NEW);
private final Observable<State> state = new Observable<>(State.INITIALIZE_APP);

public DefaultApplicationService(String[] args) {
super("default", args);
Expand Down Expand Up @@ -119,21 +121,34 @@ public DefaultApplicationService(String[] args) {
protocolService = new ProtocolService(networkService, identityService, persistenceService, offerService.getOpenOfferService());
}


// At the moment we do not initialize in parallel to keep thing simple, but can be optimized later
@Override
public CompletableFuture<Boolean> initialize() {
return securityService.initialize()
.thenCompose(result -> walletService.initialize())
.whenComplete((result, throwable) -> {
.thenCompose(result -> {
setState(State.INITIALIZE_NETWORK);

CompletableFuture<Boolean> networkFuture = networkService.initialize();
CompletableFuture<Boolean> walletFuture = walletService.initialize();

networkFuture.whenComplete((r, throwable) -> {
if (throwable != null) {
log.error("Error at networkFuture.initialize", throwable);
} else if (!walletFuture.isDone()) {
setState(State.INITIALIZE_WALLET);
}
});
walletFuture.whenComplete((r, throwable) -> {
if (throwable != null) {
log.error("Error at walletService.initialize", throwable);
}
});
return CompletableFutureUtils.allOf(walletFuture, networkFuture).thenApply(list -> true);
})
.whenComplete((r, throwable) -> {
if (throwable == null) {
setState(State.START_NETWORK);
} else {
log.error("Error at walletService.initialize", throwable);
setState(State.INITIALIZE_SERVICES);
}
})
.thenCompose(result -> networkService.initialize())
.whenComplete((r, t) -> setState(State.NETWORK_STARTED))
.thenCompose(result -> identityService.initialize())
.thenCompose(result -> oracleService.initialize())
.thenCompose(result -> accountService.initialize())
Expand All @@ -145,12 +160,17 @@ public CompletableFuture<Boolean> initialize() {
.thenCompose(result -> protocolService.initialize())
.orTimeout(5, TimeUnit.MINUTES)
.whenComplete((success, throwable) -> {
if (success) {
setState(State.INITIALIZE_COMPLETED);
log.info("NetworkApplicationService initialized");
if (throwable == null) {
if (success) {
setState(State.APP_INITIALIZED);
log.info("ApplicationService initialized");
} else {
setState(State.FAILED);
log.error("Initializing applicationService failed");
}
} else {
setState(State.INITIALIZE_FAILED);
log.error("Initializing networkApplicationService failed", throwable);
setState(State.FAILED);
log.error("Initializing applicationService failed", throwable);
}
});
}
Expand Down
10 changes: 7 additions & 3 deletions application/src/main/java/bisq/application/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ protected void launchApplication(String[] args) {
protected void onApplicationLaunched() {
applicationService.initialize()
.whenComplete((success, throwable) -> {
if (success) {
onDomainInitialized();
if (throwable == null) {
if (success) {
onDomainInitialized();
} else {
log.error("Initialize applicationService failed", throwable);
}
} else {
onInitializeDomainFailed(throwable);
}
});
}

protected void onInitializeDomainFailed(Throwable throwable) {
throwable.printStackTrace();
log.error("Initialize domain failed", throwable);
}

abstract protected void onDomainInitialized();
Expand Down
24 changes: 24 additions & 0 deletions common/src/main/java/bisq/common/util/OperatingSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.common.util;

public enum OperatingSystem {
LINUX,
MAC,
WIN
}
19 changes: 16 additions & 3 deletions common/src/main/java/bisq/common/util/OsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static File getUserDataDir() {
return new File(System.getenv("APPDATA"));
}

if (isOSX()) {
if (isMac()) {
return Paths.get(System.getProperty("user.home"), "Library", "Application Support").toFile();
}

Expand All @@ -53,7 +53,7 @@ public static boolean isWindows() {
return getOSName().contains("win");
}

public static boolean isOSX() {
public static boolean isMac() {
return getOSName().contains("mac") || getOSName().contains("darwin");
}

Expand Down Expand Up @@ -97,6 +97,19 @@ public static String getOSName() {
return System.getProperty("os.name").toLowerCase(Locale.US);
}

public static OperatingSystem getOperatingSystem() {
if (isLinux()) {
return OperatingSystem.LINUX;
} else if (isMac()) {
return OperatingSystem.MAC;
} else if (isWindows()) {
return OperatingSystem.WIN;
} else {
throw new UnsupportedOperationException("Unsupported operating system: " + OsUtils.getOSName());
}
}


public static void makeBinaryExecutable(Path binaryPath) {
boolean isSuccess = binaryPath.toFile().setExecutable(true);
if (!isSuccess) {
Expand All @@ -117,7 +130,7 @@ public static boolean open(String fileName) {
if (runCommand("xdg-open", "%s", fileName)) return true;
}

if (isOSX()) {
if (isMac()) {
if (runCommand("open", "%s", fileName)) return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@
import bisq.application.DefaultApplicationService;
import bisq.desktop.common.Browser;
import bisq.desktop.common.JavaFxApplicationData;
import bisq.desktop.common.threading.UIThread;
import bisq.desktop.common.utils.Transitions;
import bisq.desktop.common.view.Controller;
import bisq.desktop.common.view.Navigation;
import bisq.desktop.common.view.NavigationController;
import bisq.desktop.common.view.NavigationTarget;
import bisq.desktop.components.overlay.Notification;
import bisq.desktop.components.overlay.Overlay;
import bisq.desktop.components.overlay.Popup;
import bisq.desktop.primary.main.MainController;
import bisq.desktop.primary.overlay.OverlayController;
import bisq.desktop.primary.splash.SplashController;
import bisq.settings.*;
import bisq.settings.Cookie;
import bisq.settings.CookieKey;
import bisq.settings.DontShowAgainService;
import bisq.settings.SettingsService;
import javafx.application.Platform;
import javafx.geometry.Rectangle2D;
import javafx.scene.layout.AnchorPane;
Expand Down Expand Up @@ -148,15 +153,17 @@ public void onDomainInitialized() {
}

public void onUncaughtException(Thread thread, Throwable throwable) {
// todo show error popup
log.error("Uncaught exception from thread {}", thread);
log.error("Uncaught exception", throwable);
UIThread.run(() -> new Popup().error(throwable.getMessage()).show());
}

public void onQuit() {
shutdown();
}

public void onInitializeDomainFailed() {
//todo show error popup
public void onInitializeDomainFailed(Throwable throwable) {
new Popup().error(throwable.getMessage()).show();
}

public void shutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void configKeyEventHandlers() {

private Image getApplicationIconImage() {
String iconPath;
if (OsUtils.isOSX())
if (OsUtils.isMac())
iconPath = ImageUtil.isRetina() ? "images/[email protected]" : "images/window_icon.png";
else if (OsUtils.isWindows())
iconPath = "images/task_bar_icon_windows.png";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private CompletableFuture<DataService.BroadCastDataResult> doDelete() {
return userIdentityService.deleteUserProfile(userIdentityService.getSelectedUserIdentity().get())
.whenComplete((result, throwable) -> {
if (throwable != null) {
new Popup().error(throwable.getMessage()).show();
UIThread.run(() -> new Popup().error(throwable.getMessage()).show());
} else {
if (!model.getUserIdentities().isEmpty()) {
UIThread.runOnNextRenderFrame(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.application.Executable;
import bisq.common.annotations.LateInit;
import bisq.desktop.common.threading.UIThread;
import bisq.desktop.components.overlay.Popup;
import bisq.desktop.primary.PrimaryStageController;
import javafx.application.Application;
import javafx.application.Platform;
Expand Down Expand Up @@ -80,7 +81,12 @@ protected void onDomainInitialized() {
@Override
protected void onInitializeDomainFailed(Throwable throwable) {
super.onInitializeDomainFailed(throwable);
requireNonNull(primaryStageController).onInitializeDomainFailed();

if (primaryStageController == null) {
UIThread.run(() -> new Popup().error(throwable.getMessage()).show());
} else {
UIThread.run(() -> primaryStageController.onInitializeDomainFailed(throwable));
}
}

@Override
Expand Down
13 changes: 7 additions & 6 deletions i18n/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,12 @@ bisqEasy.mediation.msgToPeer=Your trade peer requested mediation support. I am a
######################################################
## ApplicationService
######################################################
applicationService.state.NEW=Starting application
applicationService.state.START_NETWORK=Bootstrap to network
applicationService.state.NETWORK_STARTED=Network bootstrapped
applicationService.state.INITIALIZE_COMPLETED=Initialization complete
applicationService.state.INITIALIZE_FAILED=Initialization failed
applicationService.state.INITIALIZE_APP=Starting Bisq
applicationService.state.INITIALIZE_NETWORK=Initialize P2P network
applicationService.state.INITIALIZE_WALLET=Initialize wallet
applicationService.state.INITIALIZE_SERVICES=Initialize services
applicationService.state.APP_INITIALIZED=Bisq started
applicationService.state.FAILED=Startup failed


######################################################
Expand Down Expand Up @@ -748,7 +749,7 @@ trade.protocols.MONERO_SWAP.tradeOffs=\
- It requires some technical skills and experience to run the required infrastructure\n\
- Confirmation time is based on the confirmations on both blockchains which will be usually about 20-30 min.\n\
- Transaction fees on the Bitcoin side could be non-trivial in case of high blockchain congestion (rather rare, though)\n\
- Both traders need to be online
- Both traders need to be online\n\
- It requires lots of fast disk storage for the nodes


Expand Down
2 changes: 1 addition & 1 deletion network/tor/src/main/java/bisq/tor/OsType.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum OsType {
public static OsType getOsType() {
if (OsUtils.isWindows()) {
return WIN;
} else if (OsUtils.isOSX()) {
} else if (OsUtils.isMac()) {
return OSX;
} else if (OsUtils.isLinux32()) {
return LINUX_32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Path extractFileWithSuffix(String fileNameSuffix) {
createDestDirIfNotPresent();

try (InputStream inputStream = openBinariesZipAsStream()) {
if (OsUtils.isOSX()) {
if (OsUtils.isMac()) {
extractElectrumAppFileToDataDir(inputStream);
return destDir.toPath().resolve("Electrum.app");

Expand Down
Loading

0 comments on commit 42ff4aa

Please sign in to comment.