Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Offline UI state. Cannot view project details in this mode. Closes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Dec 8, 2014
1 parent 04bc28f commit 73cf4c1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 57 deletions.
77 changes: 42 additions & 35 deletions client/src/main/java/lighthouse/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class Main extends Application {
private boolean slowGFX;
public String updatesURL = UPDATES_BASE_URL;

public static boolean offline = false;

public static void main(String[] args) throws IOException {
// Startup sequence: we use UpdateFX to allow for automatic online updates when the app is running. UpdateFX
// applies binary deltas to our JAR to create a new JAR that's then dropped into the app directory.
Expand Down Expand Up @@ -353,44 +355,49 @@ protected void onSetupCompleted() {
vPeerGroup.setUseLocalhostPeerWhenPossible(false);
} else {
// TODO: Replace this with a DNS seed that crawls for NODE_GETUTXOS (or whatever it's renamed to).
PeerDiscovery hardCodedPeers = new PeerDiscovery() {
@Override
public InetSocketAddress[] getPeers(long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
InetSocketAddress[] result = new InetSocketAddress[2];
result[0] = new InetSocketAddress("vinumeris.com", params.getPort());
result[1] = new InetSocketAddress("riker.plan99.net", params.getPort());
return result;
}

InetSocketAddress[] result = new InetSocketAddress[2];
result[0] = new InetSocketAddress("vinumeris.com", params.getPort());
result[1] = new InetSocketAddress("riker.plan99.net", params.getPort());

if (result[0].getAddress() == null && result[1].getAddress() == null) {
log.warn("User appears to be offline");
offline = true;
} else {
PeerDiscovery hardCodedPeers = new PeerDiscovery() {
@Override
public InetSocketAddress[] getPeers(long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
return result;
}

@Override
public void shutdown() {
}
};
vPeerGroup.addPeerDiscovery(hardCodedPeers);
vPeerGroup.setMaxConnections(2);
vPeerGroup.setConnectTimeoutMillis(10000);
// Sequence things so we *always* get both hard-coded peers for now.
vPeerGroup.waitForPeersOfVersion(2, GetUTXOsMessage.MIN_PROTOCOL_VERSION).addListener(() -> {
vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
vPeerGroup.setMaxConnections(6);
}, Threading.SAME_THREAD);
}
vPeerGroup.addEventListener(new AbstractPeerEventListener() {
@Override
public void shutdown() {
public void onPeerConnected(Peer peer, int peerCount) {
if (peer.getAddress().getAddr().isLoopbackAddress() && !peer.getPeerVersionMessage().isGetUTXOsSupported()) {
// We connected to localhost but it doesn't have what we need.
log.warn("Localhost peer does not have support for NODE_GETUTXOS, ignoring");
// TODO: Once Bitcoin Core fork name is chosen and released, be more specific in this message.
informationalAlert("Local Bitcoin node not usable",
"You have a Bitcoin (Core) node running on your computer, but it doesn't have the protocol support Lighthouse needs. Lighthouse will still " +
"work but will use the peer to peer network instead, so you won't get upgraded security.");
vPeerGroup.setUseLocalhostPeerWhenPossible(false);
vPeerGroup.setMaxConnections(4);
}
}
};
vPeerGroup.addPeerDiscovery(hardCodedPeers);
vPeerGroup.setMaxConnections(2);
vPeerGroup.setConnectTimeoutMillis(10000);
// Sequence things so we *always* get both hard-coded peers for now.
vPeerGroup.waitForPeersOfVersion(2, GetUTXOsMessage.MIN_PROTOCOL_VERSION).addListener(() -> {
vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
vPeerGroup.setMaxConnections(6);
}, Threading.SAME_THREAD);
});
}

vPeerGroup.addEventListener(new AbstractPeerEventListener() {
@Override
public void onPeerConnected(Peer peer, int peerCount) {
if (peer.getAddress().getAddr().isLoopbackAddress() && !peer.getPeerVersionMessage().isGetUTXOsSupported()) {
// We connected to localhost but it doesn't have what we need.
log.warn("Localhost peer does not have support for NODE_GETUTXOS, ignoring");
// TODO: Once Bitcoin Core fork name is chosen and released, be more specific in this message.
informationalAlert("Local Bitcoin node not usable",
"You have a Bitcoin (Core) node running on your computer, but it doesn't have the protocol support Lighthouse needs. Lighthouse will still " +
"work but will use the peer to peer network instead, so you won't get upgraded security.");
vPeerGroup.setUseLocalhostPeerWhenPossible(false);
vPeerGroup.setMaxConnections(4);
}
}
});
}
};
if (bitcoin.isChainFileLocked()) {
Expand Down
37 changes: 27 additions & 10 deletions client/src/main/java/lighthouse/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javafx.beans.Observable;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ListChangeListener;
import javafx.collections.MapChangeListener;
Expand Down Expand Up @@ -219,16 +220,24 @@ private void slideInNewProject(Project project) {

private ProjectOverviewWidget buildProjectWidget(Project project) {
SimpleObjectProperty<LighthouseBackend.ProjectState> state = new SimpleObjectProperty<>(getProjectState(project));
projectStates.addListener((javafx.beans.InvalidationListener) x -> state.set(getProjectState(project)));
ProjectOverviewWidget projectWidget = new ProjectOverviewWidget(project,
Main.backend.makeTotalPledgedProperty(project, UI_THREAD),
state);
projectWidget.onCheckStatusChanged(checkStates.get(project));
checkStates.addListener((MapChangeListener<Project, LighthouseBackend.CheckStatus>) change -> {
if (change.getKey().equals(project))
projectWidget.onCheckStatusChanged(change.wasAdded() ? change.getValueAdded() : null);
});
projectWidget.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> switchToProject(project));

ProjectOverviewWidget projectWidget;
if (Main.offline) {
state.set(LighthouseBackend.ProjectState.UNKNOWN);
projectWidget = new ProjectOverviewWidget(project, new SimpleLongProperty(0), state);
} else {
projectStates.addListener((javafx.beans.InvalidationListener) x -> state.set(getProjectState(project)));
projectWidget = new ProjectOverviewWidget(project,
Main.backend.makeTotalPledgedProperty(project, UI_THREAD),
state);
projectWidget.getStyleClass().add("project-overview-widget-clickable");
projectWidget.onCheckStatusChanged(checkStates.get(project));
checkStates.addListener((MapChangeListener<Project, LighthouseBackend.CheckStatus>) change -> {
if (change.getKey().equals(project))
projectWidget.onCheckStatusChanged(change.wasAdded() ? change.getValueAdded() : null);
});
projectWidget.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> switchToProject(project));
}
return projectWidget;
}

Expand Down Expand Up @@ -356,6 +365,12 @@ private void maybeShowReleaseNotes() {
}

private void setupBitcoinSyncNotification() {
if (Main.offline) {
Main.instance.notificationBar.displayNewItem("You are offline. You will not be able to use the app until you go online and restart.");
sendMoneyOutBtn.disableProperty().unbind();
sendMoneyOutBtn.setDisable(true);
return;
}
TorClient torClient = Main.bitcoin.peerGroup().getTorClient();
if (torClient != null) {
SimpleDoubleProperty torProgress = new SimpleDoubleProperty(-1);
Expand Down Expand Up @@ -400,6 +415,8 @@ private void doOnlineUpdateCheck() {
updater = new Updater(Main.instance.updatesURL, Main.APP_NAME, Main.VERSION, AppDirectory.dir(),
UpdateFX.findCodePath(Main.class), Main.UPDATE_SIGNING_KEYS, Main.UPDATE_SIGNING_THRESHOLD);

if (Main.offline) return;

if (!Main.instance.updatesURL.equals(Main.UPDATES_BASE_URL))
updater.setOverrideURLs(true); // For testing.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ public ProjectOverviewWidget(Project project, LongProperty pledgedAmount,
// Make the cover image go grey when claimed and blurred when loading. Make a loading indicator fade in/out.
final Image image = new Image(project.getCoverImage().newInput());
ColorAdjust colorAdjust = new ColorAdjust();
colorAdjust.saturationProperty().bind(when(equal(state, LighthouseBackend.ProjectState.CLAIMED)).then(-0.9).otherwise(0.0));
colorAdjust.saturationProperty().bind(when(
or(
equal(state, LighthouseBackend.ProjectState.CLAIMED),
equal(state, LighthouseBackend.ProjectState.UNKNOWN))
).then(-0.9).otherwise(0.0)
);
if (GuiUtils.isSoftwarePipeline()) {
// SW pipeline cannot handle gaussian blurs with acceptable performance.
coverImage.setEffect(colorAdjust);
Expand All @@ -95,7 +100,6 @@ public ProjectOverviewWidget(Project project, LongProperty pledgedAmount,
coverImage.setImage(image);
coverImage.setClip(new Rectangle(coverImage.getFitWidth(), coverImage.getFitHeight()));


animatedBind(loadingIndicatorArea, loadingIndicatorArea.opacityProperty(), when(isLoading).then(1.0).otherwise(0.0));
// Hack around a bug in jfx: progress indicator leaks the spinner animation even if it's invisible so we have
// to forcibly end the animation here to avoid burning cpu.
Expand Down
19 changes: 12 additions & 7 deletions client/src/main/java/lighthouse/subwindows/UpdateFXWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void closeClicked(ActionEvent event) {
}

public void setUpdater(Updater updater) {
if (updater.isDone())
if (updater.isDone() || Main.offline)
processUpdater(updater);
else
updater.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, event -> {
Expand All @@ -131,16 +131,21 @@ public void setUpdater(Updater updater) {
private void processUpdater(Updater updater) {
updates.clear();
updates.add(null); // Sentinel for "latest"
UpdateSummary s = null;
try {
summary = Futures.getUnchecked(updater);
if (!Main.offline)
s = Futures.getUnchecked(updater);
} catch (Exception e) {
log.warn("Failed to get online updates index, trying to fall back to disk cache: {}", e.getMessage());
}
if (s != null)
summary = s;
else
summary = loadCachedIndex();
if (summary == null) {
log.error("Not online and failed to load cached updates, showing blank window.");
pinBtn.setDisable(true);
return; // Not online and no cached updates, or some other issue, so give up.
}
if (summary == null) {
log.error("Not online and failed to load cached updates, showing blank window.");
pinBtn.setDisable(true);
return; // Not online and no cached updates, or some other issue, so give up.
}
List<UFXProtocol.Update> list = new ArrayList<>(summary.updates.getUpdatesList());
Collections.reverse(list);
Expand Down
7 changes: 5 additions & 2 deletions client/src/main/resources/lighthouse/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@
-fx-font-weight: bold;
}

.project-overview-widget:hover .project-title-label {
.project-overview-widget-clickable:hover .project-title-label {
-fx-underline: true;
}

.project-overview-widget {
-fx-cursor: hand;
-fx-border-color: derive(-vn-darkgreen, -40%);
-fx-background-color: #ffffffff;
-fx-effect: dropshadow(gaussian, grey, 3, 0.1, 1, 1);
}

.project-overview-widget-clickable {
-fx-cursor: hand;
}

.text-scrim-bottom {
-fx-background-color: linear-gradient(transparent, #333333);
}
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/java/lighthouse/LighthouseBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public static enum Mode {
public static enum ProjectState {
OPEN,
ERROR,
CLAIMED
CLAIMED,

UNKNOWN // Used only for offline mode
}

public static class CheckStatus {
Expand Down

0 comments on commit 73cf4c1

Please sign in to comment.