logs and cleanup

This commit is contained in:
Anthony Stirling 2024-12-13 16:58:34 +00:00
parent 13572a7f18
commit 509a305985
3 changed files with 22 additions and 16 deletions

View File

@ -33,9 +33,6 @@ version = "0.36.1"
java {
// 17 is lowest but we support and recommend 21
sourceCompatibility = JavaVersion.VERSION_17
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
@ -88,9 +85,9 @@ openApi {
outputFileName = "SwaggerDoc.json"
}
//0.11.5 to 2024.11.5
def getMacVersion(String version) {
def currentYear = java.time.Year.now().getValue()
// Extract everything after the first dot (or the whole string if no dot)
def versionParts = version.split("\\.", 2)
return "${currentYear}.${versionParts.length > 1 ? versionParts[1] : versionParts[0]}"
}

View File

@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import io.github.pixee.security.SystemCommand;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
@ -147,16 +148,32 @@ public class SPdfApplication {
@PostConstruct
public void init() {
log.info(
"1 STIRLING_PDF_DESKTOP_UI={}",
Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false")));
baseUrlStatic = this.baseUrl;
String url = baseUrl + ":" + getStaticPort();
if (webBrowser != null
&& Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false"))) {
webBrowser.initWebUI(url);
} else {
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
boolean browserOpen = browserOpenEnv != null && "true".equalsIgnoreCase(browserOpenEnv);
if (browserOpen) {
try {
String os = System.getProperty("os.name").toLowerCase();
Runtime rt = Runtime.getRuntime();
if (os.contains("win")) {
// For Windows
SystemCommand.runCommand(rt, "rundll32 url.dll,FileProtocolHandler " + url);
} else if (os.contains("mac")) {
SystemCommand.runCommand(rt, "open " + url);
} else if (os.contains("nix") || os.contains("nux")) {
SystemCommand.runCommand(rt, "xdg-open " + url);
}
} catch (Exception e) {
logger.error("Error opening browser: {}", e.getMessage());
}
}
}
logger.info("Running configs {}", applicationProperties.toString());
}
@PreDestroy

View File

@ -58,12 +58,10 @@ public class DesktopBrowser implements WebBrowser {
private static SystemTray systemTray;
public DesktopBrowser() {
log.info("DesktopBrowser 1");
SwingUtilities.invokeLater(
() -> {
loadingWindow = new LoadingWindow(null, "Initializing...");
loadingWindow.setVisible(true);
log.info("DesktopBrowser 2");
});
}
@ -71,10 +69,8 @@ public class DesktopBrowser implements WebBrowser {
CompletableFuture.runAsync(
() -> {
try {
log.info("DesktopBrowser 4");
CefAppBuilder builder = new CefAppBuilder();
configureCefSettings(builder);
builder.setProgressHandler(createProgressHandler());
// Build and initialize CEF
@ -94,7 +90,6 @@ public class DesktopBrowser implements WebBrowser {
// Show the frame immediately but transparent
frame.setVisible(true);
});
log.info("DesktopBrowser 5");
} catch (Exception e) {
log.error("Error initializing JCEF browser: ", e);
cleanup();
@ -156,7 +151,6 @@ public class DesktopBrowser implements WebBrowser {
Objects.requireNonNull(state, "state cannot be null");
SwingUtilities.invokeLater(
() -> {
log.info("state {}", state.name());
if (loadingWindow != null) {
switch (state) {
case LOCATING:
@ -226,7 +220,6 @@ public class DesktopBrowser implements WebBrowser {
boolean isLoading,
boolean canGoBack,
boolean canGoForward) {
log.info("Loading state changed: " + isLoading);
if (!isLoading && !browserInitialized) {
browserInitialized = true;
SwingUtilities.invokeLater(
@ -343,7 +336,6 @@ public class DesktopBrowser implements WebBrowser {
if (icon != null) {
frame.setIconImage(icon);
setupTrayIcon(icon);
log.info("Successfully set frame icon");
} else {
log.warn("Could not load icon from any source");
}