Add showcase property and rework property loading

This commit is contained in:
crschnick 2023-06-12 01:08:43 +00:00
parent 2221430c78
commit e085445344
9 changed files with 69 additions and 47 deletions

View file

@ -150,6 +150,7 @@ run {
systemProperty 'io.xpipe.app.developerMode', "true" systemProperty 'io.xpipe.app.developerMode', "true"
systemProperty 'io.xpipe.app.logLevel', "trace" systemProperty 'io.xpipe.app.logLevel', "trace"
systemProperty 'io.xpipe.app.fullVersion', rootProject.fullVersion systemProperty 'io.xpipe.app.fullVersion', rootProject.fullVersion
systemProperty 'io.xpipe.app.showcase', 'false'
// systemProperty "io.xpipe.beacon.port", "21724" // systemProperty "io.xpipe.beacon.port", "21724"
// systemProperty "io.xpipe.beacon.printMessages", "true" // systemProperty "io.xpipe.beacon.printMessages", "true"
// systemProperty 'io.xpipe.app.debugPlatform', "true" // systemProperty 'io.xpipe.app.debugPlatform', "true"
@ -173,17 +174,6 @@ task runAttachedDebugger(type: JavaExec) {
systemProperties run.systemProperties systemProperties run.systemProperties
} }
task writeBuildProperties(type: DefaultTask) {
doLast {
def resourcesDir = new File(sourceSets.main.output.resourcesDir, "io/xpipe/app/resources")
resourcesDir.mkdirs()
def contents = "version=$appVersion\n" +
"build=$appVersion-${new Date().format('yyyyMMddHHmm')}\n"
new File(resourcesDir, "app.properties").text = contents
}
}
processResources.finalizedBy(writeBuildProperties)
task writeLicenses(type: DefaultTask) { task writeLicenses(type: DefaultTask) {
doLast { doLast {
def resourcesDir = new File(sourceSets.main.output.resourcesDir, "io/xpipe/app/resources/third-party") def resourcesDir = new File(sourceSets.main.output.resourcesDir, "io/xpipe/app/resources/third-party")

View file

@ -111,7 +111,7 @@ public class BrowserModel {
} }
} }
public void openFileSystemAsync(String name, ShellStore store, String path, BooleanProperty busy) { public void openFileSystemAsync(String name, ShellStore store, String path, BooleanProperty externalBusy) {
// // Prevent multiple tabs in non browser modes // // Prevent multiple tabs in non browser modes
// if (!mode.equals(Mode.BROWSER)) { // if (!mode.equals(Mode.BROWSER)) {
// ThreadHelper.runFailableAsync(() -> { // ThreadHelper.runFailableAsync(() -> {
@ -132,9 +132,10 @@ public class BrowserModel {
ThreadHelper.runFailableAsync(() -> { ThreadHelper.runFailableAsync(() -> {
OpenFileSystemModel model; OpenFileSystemModel model;
try (var b = new BusyProperty(busy != null ? busy : new SimpleBooleanProperty())) { try (var b = new BusyProperty(externalBusy != null ? externalBusy : new SimpleBooleanProperty())) {
model = new OpenFileSystemModel(name, this, store); model = new OpenFileSystemModel(name, this, store);
model.initFileSystem(); model.initFileSystem();
model.initSavedState();
} }
openFileSystems.add(model); openFileSystems.add(model);

View file

@ -306,7 +306,6 @@ public final class OpenFileSystemModel {
this.fileSystem = fs; this.fileSystem = fs;
this.local = this.local =
fs.getShell().map(shellControl -> shellControl.isLocal()).orElse(false); fs.getShell().map(shellControl -> shellControl.isLocal()).orElse(false);
this.initState();
this.cache.init(); this.cache.init();
}); });
} }
@ -320,7 +319,7 @@ public final class OpenFileSystemModel {
history.updateCurrent(null); history.updateCurrent(null);
} }
void initState() { void initSavedState() {
this.savedState = OpenFileSystemSavedState.loadForStore(this); this.savedState = OpenFileSystemSavedState.loadForStore(this);
} }

View file

@ -86,8 +86,6 @@ public class AppLayoutComp extends Comp<CompStructure<BorderPane>> {
pane.setCenter(getRegion(n, map)); pane.setCenter(getRegion(n, map));
}); });
pane.setPrefWidth(1280);
pane.setPrefHeight(720);
AppFont.normal(pane); AppFont.normal(pane);
return new SimpleCompStructure<>(pane); return new SimpleCompStructure<>(pane);
} }

View file

@ -68,10 +68,15 @@ public class App extends Application {
var base = String.format( var base = String.format(
"XPipe Desktop (%s)", AppProperties.get().getVersion()); "XPipe Desktop (%s)", AppProperties.get().getVersion());
var prefix = AppProperties.get().isStaging() ? "[STAGE] " : ""; var prefix = AppProperties.get().isStaging() ? "[STAGE] " : "";
var suffix = XPipeDistributionType.get().getUpdateHandler().getPreparedUpdate().getValue() != null var suffix = XPipeDistributionType.get()
.getUpdateHandler()
.getPreparedUpdate()
.getValue()
!= null
? String.format( ? String.format(
" (Update to %s ready)", " (Update to %s ready)",
XPipeDistributionType.get().getUpdateHandler() XPipeDistributionType.get()
.getUpdateHandler()
.getPreparedUpdate() .getPreparedUpdate()
.getValue() .getValue()
.getVersion()) .getVersion())
@ -89,14 +94,6 @@ public class App extends Application {
stage.setOnShown(event -> { stage.setOnShown(event -> {
focus(); focus();
}); });
// For demo purposes
// if (true) {
// stage.setX(310);
// stage.setY(178);
// stage.setWidth(1300);
// stage.setHeight(730);
// }
} }
public void focus() { public void focus() {

View file

@ -7,6 +7,7 @@ import javafx.scene.image.WritableImage;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
@ -106,6 +107,18 @@ public class AppImages {
return DEFAULT_IMAGE; return DEFAULT_IMAGE;
} }
public static BufferedImage toAwtImage(Image fxImage) {
BufferedImage img = new BufferedImage(
(int) fxImage.getWidth(), (int) fxImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < fxImage.getWidth(); x++) {
for (int y = 0; y < fxImage.getHeight(); y++) {
int rgb = fxImage.getPixelReader().getArgb(x, y);
img.setRGB(x, y, rgb);
}
}
return img;
}
private static Image loadImage(Path p) { private static Image loadImage(Path p) {
if (p == null) { if (p == null) {
return DEFAULT_IMAGE; return DEFAULT_IMAGE;

View file

@ -1,6 +1,7 @@
package io.xpipe.app.core; package io.xpipe.app.core;
import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.prefs.CloseBehaviourAlert; import io.xpipe.app.prefs.CloseBehaviourAlert;
@ -19,6 +20,9 @@ import lombok.Getter;
import lombok.Value; import lombok.Value;
import lombok.extern.jackson.Jacksonized; import lombok.extern.jackson.Jacksonized;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
@ -160,9 +164,14 @@ public class AppMainWindow {
// stage.setMaximized(state.maximized); // stage.setMaximized(state.maximized);
TrackEvent.debug("Window loaded saved bounds"); TrackEvent.debug("Window loaded saved bounds");
} else { } else if (!AppProperties.get().isShowcase()) {
stage.setWidth(1280); stage.setWidth(1280);
stage.setHeight(720); stage.setHeight(720);
} else {
stage.setX(310);
stage.setY(178);
stage.setWidth(1300);
stage.setHeight(730);
} }
} }
@ -171,6 +180,10 @@ public class AppMainWindow {
return; return;
} }
if (AppProperties.get().isShowcase()) {
return;
}
var newState = WindowState.builder() var newState = WindowState.builder()
.maximized(stage.isMaximized()) .maximized(stage.isMaximized())
.windowX((int) stage.getX()) .windowX((int) stage.getX())
@ -186,6 +199,10 @@ public class AppMainWindow {
return null; return null;
} }
if (AppProperties.get().isShowcase()) {
return null;
}
WindowState state = AppCache.get("windowState", WindowState.class, () -> null); WindowState state = AppCache.get("windowState", WindowState.class, () -> null);
if (state == null) { if (state == null) {
return null; return null;
@ -232,6 +249,19 @@ public class AppMainWindow {
TrackEvent.debug("Rebuilt content"); TrackEvent.debug("Rebuilt content");
event.consume(); event.consume();
} }
if (AppProperties.get().isShowcase() && event.getCode().equals(KeyCode.F12)) {
var image = stage.getScene().getRoot().snapshot(null, null);
var awt = AppImages.toAwtImage(image);
var file = Path.of(System.getProperty("user.home"), "Desktop", "xpipe-screenshot.png");
try {
ImageIO.write(awt, "png",file.toFile());
} catch (IOException e) {
ErrorEvent.fromThrowable(e).handle();
}
TrackEvent.debug("Screenshot taken");
event.consume();
}
}); });
TrackEvent.debug("Set content reload listener"); TrackEvent.debug("Set content reload listener");
} }

View file

@ -1,16 +1,16 @@
package io.xpipe.app.core; package io.xpipe.app.core;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.core.util.ModuleHelper; import io.xpipe.core.util.ModuleHelper;
import lombok.Value; import lombok.Value;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Value @Value
public class AppProperties { public class AppProperties {
@ -28,26 +28,15 @@ public class AppProperties {
boolean image; boolean image;
boolean staging; boolean staging;
Path dataDir; Path dataDir;
boolean showcase;
public AppProperties() { public AppProperties() {
image = ModuleHelper.isImage(); image = ModuleHelper.isImage();
Properties props = new Properties();
AppResources.with(AppResources.XPIPE_MODULE, "app.properties", p -> {
if (Files.exists(p)) {
try (var in = Files.newInputStream(p)) {
props.load(in);
} catch (IOException e) {
ErrorEvent.fromThrowable(e).omitted(true).build().handle();
}
}
});
fullVersion = Optional.ofNullable(System.getProperty("io.xpipe.app.fullVersion")) fullVersion = Optional.ofNullable(System.getProperty("io.xpipe.app.fullVersion"))
.map(Boolean::parseBoolean) .map(Boolean::parseBoolean)
.orElse(false); .orElse(false);
version = Optional.ofNullable(props.getProperty("version")).orElse("dev"); version = Optional.ofNullable(System.getProperty("io.xpipe.app.version")).orElse("dev");
build = Optional.ofNullable(props.getProperty("build")).orElse("unknown"); build = Optional.ofNullable(System.getProperty("io.xpipe.app.build")).orElse("unknown");
buildUuid = Optional.ofNullable(System.getProperty("io.xpipe.app.buildId")) buildUuid = Optional.ofNullable(System.getProperty("io.xpipe.app.buildId"))
.map(UUID::fromString) .map(UUID::fromString)
.orElse(UUID.randomUUID()); .orElse(UUID.randomUUID());
@ -57,6 +46,9 @@ public class AppProperties {
staging = Optional.ofNullable(System.getProperty("io.xpipe.app.staging")) staging = Optional.ofNullable(System.getProperty("io.xpipe.app.staging"))
.map(Boolean::parseBoolean) .map(Boolean::parseBoolean)
.orElse(false); .orElse(false);
showcase = Optional.ofNullable(System.getProperty("io.xpipe.app.showcase"))
.map(Boolean::parseBoolean)
.orElse(false);
} }
public static void logSystemProperties() { public static void logSystemProperties() {

View file

@ -6,6 +6,8 @@ def distJvmArgs = new ArrayList<String>(project(':app').application.applicationD
def releaseArguments = distJvmArgs + [ def releaseArguments = distJvmArgs + [
'-Dio.xpipe.app.writeLogs=true', '-Dio.xpipe.app.writeLogs=true',
"-Dio.xpipe.app.version=$rootProject.versionString",
"-Dio.xpipe.app.build=$rootProject.versionString-${new Date().format('yyyyMMddHHmm')}",
"-Dio.xpipe.app.buildId=$rootProject.buildId", "-Dio.xpipe.app.buildId=$rootProject.buildId",
"-Dio.xpipe.app.fullVersion=$rootProject.fullVersion", "-Dio.xpipe.app.fullVersion=$rootProject.fullVersion",
"-Dio.xpipe.app.staging=$rootProject.isStage", "-Dio.xpipe.app.staging=$rootProject.isStage",