Skip to content

Commit

Permalink
Merge pull request #4415 from sqrrm/dev-css
Browse files Browse the repository at this point in the history
Add option to use different css for dev mode
  • Loading branch information
ripcurlx authored Sep 2, 2020
2 parents a691eed + f0acec0 commit 095c8b5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/bisq/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class Config {
public static final String BASE_CURRENCY_NETWORK = "baseCurrencyNetwork";
public static final String REFERRAL_ID = "referralId";
public static final String USE_DEV_MODE = "useDevMode";
public static final String USE_DEV_MODE_HEADER = "useDevModeHeader";
public static final String TOR_DIR = "torDir";
public static final String STORAGE_DIR = "storageDir";
public static final String KEY_STORAGE_DIR = "keyStorageDir";
Expand Down Expand Up @@ -159,6 +160,7 @@ public class Config {
public final boolean daoActivated;
public final String referralId;
public final boolean useDevMode;
public final boolean useDevModeHeader;
public final boolean useDevPrivilegeKeys;
public final boolean dumpStatistics;
public final boolean ignoreDevMsg;
Expand Down Expand Up @@ -356,6 +358,13 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
.ofType(boolean.class)
.defaultsTo(false);

ArgumentAcceptingOptionSpec<Boolean> useDevModeHeaderOpt =
parser.accepts(USE_DEV_MODE_HEADER,
"Use dev mode css scheme to distinguish dev instances.")
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);

ArgumentAcceptingOptionSpec<Boolean> useDevPrivilegeKeysOpt =
parser.accepts(USE_DEV_PRIVILEGE_KEYS, "If set to true all privileged features requiring a private " +
"key to be enabled are overridden by a dev key pair (This is for developers only!)")
Expand Down Expand Up @@ -706,6 +715,7 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
this.torStreamIsolation = options.has(torStreamIsolationOpt);
this.referralId = options.valueOf(referralIdOpt);
this.useDevMode = options.valueOf(useDevModeOpt);
this.useDevModeHeader = options.valueOf(useDevModeHeaderOpt);
this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt);
this.dumpStatistics = options.valueOf(dumpStatisticsOpt);
this.ignoreDevMsg = options.valueOf(ignoreDevMsgOpt);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ protected void applyInjector() {

protected void setupDevEnv() {
DevEnv.setDevMode(config.useDevMode);
DevEnv.setDevMode(config.useDevModeHeader);
DevEnv.setDaoActivated(config.daoActivated);
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/app/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected void configure() {

bindConstant().annotatedWith(named(USE_DEV_PRIVILEGE_KEYS)).to(config.useDevPrivilegeKeys);
bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.useDevMode);
bindConstant().annotatedWith(named(USE_DEV_MODE_HEADER)).to(config.useDevModeHeader);
bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.referralId);

// ordering is used for shut down sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected void configure() {

bindConstant().annotatedWith(named(USE_DEV_PRIVILEGE_KEYS)).to(config.useDevPrivilegeKeys);
bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.useDevMode);
bindConstant().annotatedWith(named(USE_DEV_MODE_HEADER)).to(config.useDevModeHeader);
bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.referralId);

// ordering is used for shut down sequence
Expand Down
7 changes: 4 additions & 3 deletions desktop/src/main/java/bisq/desktop/app/BisqApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void handleUncaughtException(Throwable throwable, boolean doShutDown) {
if (scene == null) {
log.warn("Scene not available yet, we create a new scene. The bug might be caused by an exception in a constructor or by a circular dependency in Guice. throwable=" + throwable.toString());
scene = new Scene(new StackPane(), 1000, 650);
CssTheme.loadSceneStyles(scene, CssTheme.CSS_THEME_LIGHT);
CssTheme.loadSceneStyles(scene, CssTheme.CSS_THEME_LIGHT, false);
stage.setScene(scene);
stage.show();
}
Expand Down Expand Up @@ -221,10 +221,11 @@ private Scene createAndConfigScene(MainView mainView, Injector injector) {
addSceneKeyEventHandler(scene, injector);

Preferences preferences = injector.getInstance(Preferences.class);
var config = injector.getInstance(Config.class);
preferences.getCssThemeProperty().addListener((ov) -> {
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
CssTheme.loadSceneStyles(scene, preferences.getCssTheme(), config.useDevModeHeader);
});
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
CssTheme.loadSceneStyles(scene, preferences.getCssTheme(), config.useDevModeHeader);

return scene;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
private final CoinFormatter formatter;
private final PrivateNotificationManager privateNotificationManager;
private final boolean useDevPrivilegeKeys;
private final boolean useDevModeHeader;
private final Preferences preferences;
@FXML
TableView<PendingTradesListItem> tableView;
Expand Down Expand Up @@ -141,13 +142,15 @@ public PendingTradesView(PendingTradesViewModel model,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter,
PrivateNotificationManager privateNotificationManager,
Preferences preferences,
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys) {
@Named(Config.USE_DEV_PRIVILEGE_KEYS) boolean useDevPrivilegeKeys,
@Named(Config.USE_DEV_MODE_HEADER) boolean useDevModeHeader) {
super(model);
this.tradeDetailsWindow = tradeDetailsWindow;
this.formatter = formatter;
this.privateNotificationManager = privateNotificationManager;
this.preferences = preferences;
this.useDevPrivilegeKeys = useDevPrivilegeKeys;
this.useDevModeHeader = useDevModeHeader;
}

@Override
Expand Down Expand Up @@ -412,7 +415,7 @@ private void openChat(Trade trade) {
});

Scene scene = new Scene(pane);
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
CssTheme.loadSceneStyles(scene, preferences.getCssTheme(), useDevModeHeader);
scene.addEventHandler(KeyEvent.KEY_RELEASED, ev -> {
if (ev.getCode() == KeyCode.ESCAPE) {
ev.consume();
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/main/java/bisq/desktop/theme-dev.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.root {
-bs-rd-nav-background: #841413;
-bs-rd-nav-primary-background: #841413;
}
6 changes: 5 additions & 1 deletion desktop/src/main/java/bisq/desktop/util/CssTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public class CssTheme {
public static final int CSS_THEME_DARK = 1;

private static int currentCSSTheme;
private static boolean useDevHeader;

public static void loadSceneStyles(Scene scene, int cssTheme) {
public static void loadSceneStyles(Scene scene, int cssTheme, boolean devHeader) {
String cssThemeFolder = "/bisq/desktop/";
String cssThemeFile = "";

currentCSSTheme = cssTheme;
useDevHeader = devHeader;

switch (cssTheme) {

Expand All @@ -52,6 +54,8 @@ public static void loadSceneStyles(Scene scene, int cssTheme) {
// load theme last to allow override
cssThemeFolder + cssThemeFile
);
if (useDevHeader)
scene.getStylesheets().add(cssThemeFolder + "theme-dev.css");
}

public static boolean isDarkTheme() {
Expand Down

0 comments on commit 095c8b5

Please sign in to comment.