mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 22:29:24 +00:00
Remove desktopBrowser File
This commit is contained in:
parent
70d66bbcbe
commit
679d3efc81
2
.github/workflows/tauri-test.yml
vendored
2
.github/workflows/tauri-test.yml
vendored
@ -113,7 +113,7 @@ jobs:
|
|||||||
chmod +x ./gradlew
|
chmod +x ./gradlew
|
||||||
echo "🔧 Building Stirling-PDF JAR..."
|
echo "🔧 Building Stirling-PDF JAR..."
|
||||||
# STIRLING_PDF_DESKTOP_UI=false ./gradlew clean bootJar --no-daemon
|
# STIRLING_PDF_DESKTOP_UI=false ./gradlew clean bootJar --no-daemon
|
||||||
STIRLING_PDF_DESKTOP_UI=false ./gradlew clean build -x spotlessApply -x spotlessCheck -x test -x sonarqube
|
./gradlew clean build -x spotlessApply -x spotlessCheck -x test -x sonarqube
|
||||||
|
|
||||||
# Find the built JAR
|
# Find the built JAR
|
||||||
STIRLING_JAR=$(ls stirling-pdf/build/libs/stirling-pdf-*.jar | head -n 1)
|
STIRLING_JAR=$(ls stirling-pdf/build/libs/stirling-pdf-*.jar | head -n 1)
|
||||||
|
@ -29,7 +29,7 @@ dependencies {
|
|||||||
if (System.getenv('STIRLING_PDF_DESKTOP_UI') != 'false'
|
if (System.getenv('STIRLING_PDF_DESKTOP_UI') != 'false'
|
||||||
|| (project.hasProperty('STIRLING_PDF_DESKTOP_UI')
|
|| (project.hasProperty('STIRLING_PDF_DESKTOP_UI')
|
||||||
&& project.getProperty('STIRLING_PDF_DESKTOP_UI') != 'false')) {
|
&& project.getProperty('STIRLING_PDF_DESKTOP_UI') != 'false')) {
|
||||||
implementation 'me.friwi:jcefmaven:132.3.1'
|
// implementation 'me.friwi:jcefmaven:132.3.1'
|
||||||
implementation 'org.openjfx:javafx-controls:21'
|
implementation 'org.openjfx:javafx-controls:21'
|
||||||
implementation 'org.openjfx:javafx-swing:21'
|
implementation 'org.openjfx:javafx-swing:21'
|
||||||
}
|
}
|
||||||
|
@ -1,497 +1,497 @@
|
|||||||
package stirling.software.SPDF.UI.impl;
|
// package stirling.software.SPDF.UI.impl;
|
||||||
|
|
||||||
import java.awt.AWTException;
|
// import java.awt.AWTException;
|
||||||
import java.awt.BorderLayout;
|
// import java.awt.BorderLayout;
|
||||||
import java.awt.Frame;
|
// import java.awt.Frame;
|
||||||
import java.awt.Image;
|
// import java.awt.Image;
|
||||||
import java.awt.MenuItem;
|
// import java.awt.MenuItem;
|
||||||
import java.awt.PopupMenu;
|
// import java.awt.PopupMenu;
|
||||||
import java.awt.SystemTray;
|
// import java.awt.SystemTray;
|
||||||
import java.awt.TrayIcon;
|
// import java.awt.TrayIcon;
|
||||||
import java.awt.event.WindowEvent;
|
// import java.awt.event.WindowEvent;
|
||||||
import java.awt.event.WindowStateListener;
|
// import java.awt.event.WindowStateListener;
|
||||||
import java.io.File;
|
// import java.io.File;
|
||||||
import java.io.InputStream;
|
// import java.io.InputStream;
|
||||||
import java.util.Objects;
|
// import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
// import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
// import javax.imageio.ImageIO;
|
||||||
import javax.swing.JFrame;
|
// import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
// import javax.swing.JPanel;
|
||||||
import javax.swing.SwingUtilities;
|
// import javax.swing.SwingUtilities;
|
||||||
import javax.swing.Timer;
|
// import javax.swing.Timer;
|
||||||
|
|
||||||
import org.cef.CefApp;
|
// import org.cef.CefApp;
|
||||||
import org.cef.CefClient;
|
// import org.cef.CefClient;
|
||||||
import org.cef.CefSettings;
|
// import org.cef.CefSettings;
|
||||||
import org.cef.browser.CefBrowser;
|
// import org.cef.browser.CefBrowser;
|
||||||
import org.cef.callback.CefBeforeDownloadCallback;
|
// import org.cef.callback.CefBeforeDownloadCallback;
|
||||||
import org.cef.callback.CefDownloadItem;
|
// import org.cef.callback.CefDownloadItem;
|
||||||
import org.cef.callback.CefDownloadItemCallback;
|
// import org.cef.callback.CefDownloadItemCallback;
|
||||||
import org.cef.handler.CefDownloadHandlerAdapter;
|
// import org.cef.handler.CefDownloadHandlerAdapter;
|
||||||
import org.cef.handler.CefLoadHandlerAdapter;
|
// import org.cef.handler.CefLoadHandlerAdapter;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
// import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Component;
|
// import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import jakarta.annotation.PreDestroy;
|
// import jakarta.annotation.PreDestroy;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
// import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import me.friwi.jcefmaven.CefAppBuilder;
|
// import me.friwi.jcefmaven.CefAppBuilder;
|
||||||
import me.friwi.jcefmaven.EnumProgress;
|
// import me.friwi.jcefmaven.EnumProgress;
|
||||||
import me.friwi.jcefmaven.MavenCefAppHandlerAdapter;
|
// import me.friwi.jcefmaven.MavenCefAppHandlerAdapter;
|
||||||
import me.friwi.jcefmaven.impl.progress.ConsoleProgressHandler;
|
// import me.friwi.jcefmaven.impl.progress.ConsoleProgressHandler;
|
||||||
|
|
||||||
import stirling.software.SPDF.UI.WebBrowser;
|
// import stirling.software.SPDF.UI.WebBrowser;
|
||||||
import stirling.software.common.configuration.InstallationPathConfig;
|
// import stirling.software.common.configuration.InstallationPathConfig;
|
||||||
import stirling.software.common.util.UIScaling;
|
// import stirling.software.common.util.UIScaling;
|
||||||
|
|
||||||
@Component
|
// @Component
|
||||||
@Slf4j
|
// @Slf4j
|
||||||
@ConditionalOnProperty(
|
// @ConditionalOnProperty(
|
||||||
name = "STIRLING_PDF_DESKTOP_UI",
|
// name = "STIRLING_PDF_DESKTOP_UI",
|
||||||
havingValue = "true",
|
// havingValue = "true",
|
||||||
matchIfMissing = false)
|
// matchIfMissing = false)
|
||||||
public class DesktopBrowser implements WebBrowser {
|
// public class DesktopBrowser implements WebBrowser {
|
||||||
private static CefApp cefApp;
|
// private static CefApp cefApp;
|
||||||
private static CefClient client;
|
// private static CefClient client;
|
||||||
private static CefBrowser browser;
|
// private static CefBrowser browser;
|
||||||
private static JFrame frame;
|
// private static JFrame frame;
|
||||||
private static LoadingWindow loadingWindow;
|
// private static LoadingWindow loadingWindow;
|
||||||
private static volatile boolean browserInitialized = false;
|
// private static volatile boolean browserInitialized = false;
|
||||||
private static TrayIcon trayIcon;
|
// private static TrayIcon trayIcon;
|
||||||
private static SystemTray systemTray;
|
// private static SystemTray systemTray;
|
||||||
|
|
||||||
public DesktopBrowser() {
|
// public DesktopBrowser() {
|
||||||
SwingUtilities.invokeLater(
|
// SwingUtilities.invokeLater(
|
||||||
() -> {
|
// () -> {
|
||||||
loadingWindow = new LoadingWindow(null, "Initializing...");
|
// loadingWindow = new LoadingWindow(null, "Initializing...");
|
||||||
loadingWindow.setVisible(true);
|
// loadingWindow.setVisible(true);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void initWebUI(String url) {
|
// public void initWebUI(String url) {
|
||||||
CompletableFuture.runAsync(
|
// CompletableFuture.runAsync(
|
||||||
() -> {
|
// () -> {
|
||||||
try {
|
// try {
|
||||||
CefAppBuilder builder = new CefAppBuilder();
|
// CefAppBuilder builder = new CefAppBuilder();
|
||||||
configureCefSettings(builder);
|
// configureCefSettings(builder);
|
||||||
builder.setProgressHandler(createProgressHandler());
|
// builder.setProgressHandler(createProgressHandler());
|
||||||
builder.setInstallDir(
|
// builder.setInstallDir(
|
||||||
new File(InstallationPathConfig.getClientWebUIPath()));
|
// new File(InstallationPathConfig.getClientWebUIPath()));
|
||||||
// Build and initialize CEF
|
// // Build and initialize CEF
|
||||||
cefApp = builder.build();
|
// cefApp = builder.build();
|
||||||
client = cefApp.createClient();
|
// client = cefApp.createClient();
|
||||||
|
|
||||||
// Set up download handler
|
// // Set up download handler
|
||||||
setupDownloadHandler();
|
// setupDownloadHandler();
|
||||||
|
|
||||||
// Create browser and frame on EDT
|
// // Create browser and frame on EDT
|
||||||
SwingUtilities.invokeAndWait(
|
// SwingUtilities.invokeAndWait(
|
||||||
() -> {
|
// () -> {
|
||||||
browser = client.createBrowser(url, false, false);
|
// browser = client.createBrowser(url, false, false);
|
||||||
setupMainFrame();
|
// setupMainFrame();
|
||||||
setupLoadHandler();
|
// setupLoadHandler();
|
||||||
|
|
||||||
// Force initialize UI after 7 seconds if not already done
|
// // Force initialize UI after 7 seconds if not already done
|
||||||
Timer timeoutTimer =
|
// Timer timeoutTimer =
|
||||||
new Timer(
|
// new Timer(
|
||||||
2500,
|
// 2500,
|
||||||
e -> {
|
// e -> {
|
||||||
log.warn(
|
// log.warn(
|
||||||
"Loading timeout reached. Forcing"
|
// "Loading timeout reached. Forcing"
|
||||||
+ " UI transition.");
|
// + " UI transition.");
|
||||||
if (!browserInitialized) {
|
// if (!browserInitialized) {
|
||||||
// Force UI initialization
|
// // Force UI initialization
|
||||||
forceInitializeUI();
|
// forceInitializeUI();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
timeoutTimer.setRepeats(false);
|
// timeoutTimer.setRepeats(false);
|
||||||
timeoutTimer.start();
|
// timeoutTimer.start();
|
||||||
});
|
// });
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("Error initializing JCEF browser: ", e);
|
// log.error("Error initializing JCEF browser: ", e);
|
||||||
cleanup();
|
// cleanup();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void configureCefSettings(CefAppBuilder builder) {
|
// private void configureCefSettings(CefAppBuilder builder) {
|
||||||
CefSettings settings = builder.getCefSettings();
|
// CefSettings settings = builder.getCefSettings();
|
||||||
String basePath = InstallationPathConfig.getClientWebUIPath();
|
// String basePath = InstallationPathConfig.getClientWebUIPath();
|
||||||
log.info("basePath " + basePath);
|
// log.info("basePath " + basePath);
|
||||||
settings.cache_path = new File(basePath + "cache").getAbsolutePath();
|
// settings.cache_path = new File(basePath + "cache").getAbsolutePath();
|
||||||
settings.root_cache_path = new File(basePath + "root_cache").getAbsolutePath();
|
// settings.root_cache_path = new File(basePath + "root_cache").getAbsolutePath();
|
||||||
// settings.browser_subprocess_path = new File(basePath +
|
// // settings.browser_subprocess_path = new File(basePath +
|
||||||
// "subprocess").getAbsolutePath();
|
// // "subprocess").getAbsolutePath();
|
||||||
// settings.resources_dir_path = new File(basePath + "resources").getAbsolutePath();
|
// // settings.resources_dir_path = new File(basePath + "resources").getAbsolutePath();
|
||||||
// settings.locales_dir_path = new File(basePath + "locales").getAbsolutePath();
|
// // settings.locales_dir_path = new File(basePath + "locales").getAbsolutePath();
|
||||||
settings.log_file = new File(basePath, "debug.log").getAbsolutePath();
|
// settings.log_file = new File(basePath, "debug.log").getAbsolutePath();
|
||||||
|
|
||||||
settings.persist_session_cookies = true;
|
// settings.persist_session_cookies = true;
|
||||||
settings.windowless_rendering_enabled = false;
|
// settings.windowless_rendering_enabled = false;
|
||||||
settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_INFO;
|
// settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_INFO;
|
||||||
|
|
||||||
builder.setAppHandler(
|
// builder.setAppHandler(
|
||||||
new MavenCefAppHandlerAdapter() {
|
// new MavenCefAppHandlerAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public void stateHasChanged(org.cef.CefApp.CefAppState state) {
|
// public void stateHasChanged(org.cef.CefApp.CefAppState state) {
|
||||||
log.info("CEF state changed: " + state);
|
// log.info("CEF state changed: " + state);
|
||||||
if (state == CefApp.CefAppState.TERMINATED) {
|
// if (state == CefApp.CefAppState.TERMINATED) {
|
||||||
System.exit(0);
|
// System.exit(0);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void setupDownloadHandler() {
|
// private void setupDownloadHandler() {
|
||||||
client.addDownloadHandler(
|
// client.addDownloadHandler(
|
||||||
new CefDownloadHandlerAdapter() {
|
// new CefDownloadHandlerAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public boolean onBeforeDownload(
|
// public boolean onBeforeDownload(
|
||||||
CefBrowser browser,
|
// CefBrowser browser,
|
||||||
CefDownloadItem downloadItem,
|
// CefDownloadItem downloadItem,
|
||||||
String suggestedName,
|
// String suggestedName,
|
||||||
CefBeforeDownloadCallback callback) {
|
// CefBeforeDownloadCallback callback) {
|
||||||
callback.Continue("", true);
|
// callback.Continue("", true);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void onDownloadUpdated(
|
// public void onDownloadUpdated(
|
||||||
CefBrowser browser,
|
// CefBrowser browser,
|
||||||
CefDownloadItem downloadItem,
|
// CefDownloadItem downloadItem,
|
||||||
CefDownloadItemCallback callback) {
|
// CefDownloadItemCallback callback) {
|
||||||
if (downloadItem.isComplete()) {
|
// if (downloadItem.isComplete()) {
|
||||||
log.info("Download completed: " + downloadItem.getFullPath());
|
// log.info("Download completed: " + downloadItem.getFullPath());
|
||||||
} else if (downloadItem.isCanceled()) {
|
// } else if (downloadItem.isCanceled()) {
|
||||||
log.info("Download canceled: " + downloadItem.getFullPath());
|
// log.info("Download canceled: " + downloadItem.getFullPath());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private ConsoleProgressHandler createProgressHandler() {
|
// private ConsoleProgressHandler createProgressHandler() {
|
||||||
return new ConsoleProgressHandler() {
|
// return new ConsoleProgressHandler() {
|
||||||
@Override
|
// @Override
|
||||||
public void handleProgress(EnumProgress state, float percent) {
|
// public void handleProgress(EnumProgress state, float percent) {
|
||||||
Objects.requireNonNull(state, "state cannot be null");
|
// Objects.requireNonNull(state, "state cannot be null");
|
||||||
SwingUtilities.invokeLater(
|
// SwingUtilities.invokeLater(
|
||||||
() -> {
|
// () -> {
|
||||||
if (loadingWindow != null) {
|
// if (loadingWindow != null) {
|
||||||
switch (state) {
|
// switch (state) {
|
||||||
case LOCATING:
|
// case LOCATING:
|
||||||
loadingWindow.setStatus("Locating Files...");
|
// loadingWindow.setStatus("Locating Files...");
|
||||||
loadingWindow.setProgress(0);
|
// loadingWindow.setProgress(0);
|
||||||
break;
|
// break;
|
||||||
case DOWNLOADING:
|
// case DOWNLOADING:
|
||||||
if (percent >= 0) {
|
// if (percent >= 0) {
|
||||||
loadingWindow.setStatus(
|
// loadingWindow.setStatus(
|
||||||
String.format(
|
// String.format(
|
||||||
"Downloading additional files: %.0f%%",
|
// "Downloading additional files: %.0f%%",
|
||||||
percent));
|
// percent));
|
||||||
loadingWindow.setProgress((int) percent);
|
// loadingWindow.setProgress((int) percent);
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
case EXTRACTING:
|
// case EXTRACTING:
|
||||||
loadingWindow.setStatus("Extracting files...");
|
// loadingWindow.setStatus("Extracting files...");
|
||||||
loadingWindow.setProgress(60);
|
// loadingWindow.setProgress(60);
|
||||||
break;
|
// break;
|
||||||
case INITIALIZING:
|
// case INITIALIZING:
|
||||||
loadingWindow.setStatus("Initializing UI...");
|
// loadingWindow.setStatus("Initializing UI...");
|
||||||
loadingWindow.setProgress(80);
|
// loadingWindow.setProgress(80);
|
||||||
break;
|
// break;
|
||||||
case INITIALIZED:
|
// case INITIALIZED:
|
||||||
loadingWindow.setStatus("Finalising startup...");
|
// loadingWindow.setStatus("Finalising startup...");
|
||||||
loadingWindow.setProgress(90);
|
// loadingWindow.setProgress(90);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void setupMainFrame() {
|
// private void setupMainFrame() {
|
||||||
frame = new JFrame("Stirling-PDF");
|
// frame = new JFrame("Stirling-PDF");
|
||||||
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
// frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
frame.setUndecorated(true);
|
// frame.setUndecorated(true);
|
||||||
frame.setOpacity(0.0f);
|
// frame.setOpacity(0.0f);
|
||||||
|
|
||||||
JPanel contentPane = new JPanel(new BorderLayout());
|
// JPanel contentPane = new JPanel(new BorderLayout());
|
||||||
contentPane.setDoubleBuffered(true);
|
// contentPane.setDoubleBuffered(true);
|
||||||
contentPane.add(browser.getUIComponent(), BorderLayout.CENTER);
|
// contentPane.add(browser.getUIComponent(), BorderLayout.CENTER);
|
||||||
frame.setContentPane(contentPane);
|
// frame.setContentPane(contentPane);
|
||||||
|
|
||||||
frame.addWindowListener(
|
// frame.addWindowListener(
|
||||||
new java.awt.event.WindowAdapter() {
|
// new java.awt.event.WindowAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
// public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
||||||
cleanup();
|
// cleanup();
|
||||||
System.exit(0);
|
// System.exit(0);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
frame.setSize(UIScaling.scaleWidth(1280), UIScaling.scaleHeight(800));
|
// frame.setSize(UIScaling.scaleWidth(1280), UIScaling.scaleHeight(800));
|
||||||
frame.setLocationRelativeTo(null);
|
// frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
loadIcon();
|
// loadIcon();
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void setupLoadHandler() {
|
// private void setupLoadHandler() {
|
||||||
final long initStartTime = System.currentTimeMillis();
|
// final long initStartTime = System.currentTimeMillis();
|
||||||
log.info("Setting up load handler at: {}", initStartTime);
|
// log.info("Setting up load handler at: {}", initStartTime);
|
||||||
|
|
||||||
client.addLoadHandler(
|
// client.addLoadHandler(
|
||||||
new CefLoadHandlerAdapter() {
|
// new CefLoadHandlerAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public void onLoadingStateChange(
|
// public void onLoadingStateChange(
|
||||||
CefBrowser browser,
|
// CefBrowser browser,
|
||||||
boolean isLoading,
|
// boolean isLoading,
|
||||||
boolean canGoBack,
|
// boolean canGoBack,
|
||||||
boolean canGoForward) {
|
// boolean canGoForward) {
|
||||||
log.debug(
|
// log.debug(
|
||||||
"Loading state change - isLoading: {}, canGoBack: {}, canGoForward:"
|
// "Loading state change - isLoading: {}, canGoBack: {}, canGoForward:"
|
||||||
+ " {}, browserInitialized: {}, Time elapsed: {}ms",
|
// + " {}, browserInitialized: {}, Time elapsed: {}ms",
|
||||||
isLoading,
|
// isLoading,
|
||||||
canGoBack,
|
// canGoBack,
|
||||||
canGoForward,
|
// canGoForward,
|
||||||
browserInitialized,
|
// browserInitialized,
|
||||||
System.currentTimeMillis() - initStartTime);
|
// System.currentTimeMillis() - initStartTime);
|
||||||
|
|
||||||
if (!isLoading && !browserInitialized) {
|
// if (!isLoading && !browserInitialized) {
|
||||||
log.info(
|
// log.info(
|
||||||
"Browser finished loading, preparing to initialize UI"
|
// "Browser finished loading, preparing to initialize UI"
|
||||||
+ " components");
|
// + " components");
|
||||||
browserInitialized = true;
|
// browserInitialized = true;
|
||||||
SwingUtilities.invokeLater(
|
// SwingUtilities.invokeLater(
|
||||||
() -> {
|
// () -> {
|
||||||
try {
|
// try {
|
||||||
if (loadingWindow != null) {
|
// if (loadingWindow != null) {
|
||||||
log.info("Starting UI initialization sequence");
|
// log.info("Starting UI initialization sequence");
|
||||||
|
|
||||||
// Close loading window first
|
// // Close loading window first
|
||||||
loadingWindow.setVisible(false);
|
// loadingWindow.setVisible(false);
|
||||||
loadingWindow.dispose();
|
// loadingWindow.dispose();
|
||||||
loadingWindow = null;
|
// loadingWindow = null;
|
||||||
log.info("Loading window disposed");
|
// log.info("Loading window disposed");
|
||||||
|
|
||||||
// Then setup the main frame
|
// // Then setup the main frame
|
||||||
frame.setVisible(false);
|
// frame.setVisible(false);
|
||||||
frame.dispose();
|
// frame.dispose();
|
||||||
frame.setOpacity(1.0f);
|
// frame.setOpacity(1.0f);
|
||||||
frame.setUndecorated(false);
|
// frame.setUndecorated(false);
|
||||||
frame.pack();
|
// frame.pack();
|
||||||
frame.setSize(
|
// frame.setSize(
|
||||||
UIScaling.scaleWidth(1280),
|
// UIScaling.scaleWidth(1280),
|
||||||
UIScaling.scaleHeight(800));
|
// UIScaling.scaleHeight(800));
|
||||||
frame.setLocationRelativeTo(null);
|
// frame.setLocationRelativeTo(null);
|
||||||
log.debug("Frame reconfigured");
|
// log.debug("Frame reconfigured");
|
||||||
|
|
||||||
// Show the main frame
|
// // Show the main frame
|
||||||
frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
frame.requestFocus();
|
// frame.requestFocus();
|
||||||
frame.toFront();
|
// frame.toFront();
|
||||||
log.info("Main frame displayed and focused");
|
// log.info("Main frame displayed and focused");
|
||||||
|
|
||||||
// Focus the browser component
|
// // Focus the browser component
|
||||||
Timer focusTimer =
|
// Timer focusTimer =
|
||||||
new Timer(
|
// new Timer(
|
||||||
100,
|
// 100,
|
||||||
e -> {
|
// e -> {
|
||||||
try {
|
// try {
|
||||||
browser.getUIComponent()
|
// browser.getUIComponent()
|
||||||
.requestFocus();
|
// .requestFocus();
|
||||||
log.info(
|
// log.info(
|
||||||
"Browser component"
|
// "Browser component"
|
||||||
+ " focused");
|
// + " focused");
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
log.error(
|
// log.error(
|
||||||
"Error focusing"
|
// "Error focusing"
|
||||||
+ " browser",
|
// + " browser",
|
||||||
ex);
|
// ex);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
focusTimer.setRepeats(false);
|
// focusTimer.setRepeats(false);
|
||||||
focusTimer.start();
|
// focusTimer.start();
|
||||||
}
|
// }
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("Error during UI initialization", e);
|
// log.error("Error during UI initialization", e);
|
||||||
// Attempt cleanup on error
|
// // Attempt cleanup on error
|
||||||
if (loadingWindow != null) {
|
// if (loadingWindow != null) {
|
||||||
loadingWindow.dispose();
|
// loadingWindow.dispose();
|
||||||
loadingWindow = null;
|
// loadingWindow = null;
|
||||||
}
|
// }
|
||||||
if (frame != null) {
|
// if (frame != null) {
|
||||||
frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
frame.requestFocus();
|
// frame.requestFocus();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void setupTrayIcon(Image icon) {
|
// private void setupTrayIcon(Image icon) {
|
||||||
if (!SystemTray.isSupported()) {
|
// if (!SystemTray.isSupported()) {
|
||||||
log.warn("System tray is not supported");
|
// log.warn("System tray is not supported");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
systemTray = SystemTray.getSystemTray();
|
// systemTray = SystemTray.getSystemTray();
|
||||||
|
|
||||||
// Create popup menu
|
// // Create popup menu
|
||||||
PopupMenu popup = new PopupMenu();
|
// PopupMenu popup = new PopupMenu();
|
||||||
|
|
||||||
// Create menu items
|
// // Create menu items
|
||||||
MenuItem showItem = new MenuItem("Show");
|
// MenuItem showItem = new MenuItem("Show");
|
||||||
showItem.addActionListener(
|
// showItem.addActionListener(
|
||||||
e -> {
|
// e -> {
|
||||||
frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
frame.setState(Frame.NORMAL);
|
// frame.setState(Frame.NORMAL);
|
||||||
});
|
// });
|
||||||
|
|
||||||
MenuItem exitItem = new MenuItem("Exit");
|
// MenuItem exitItem = new MenuItem("Exit");
|
||||||
exitItem.addActionListener(
|
// exitItem.addActionListener(
|
||||||
e -> {
|
// e -> {
|
||||||
cleanup();
|
// cleanup();
|
||||||
System.exit(0);
|
// System.exit(0);
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Add menu items to popup menu
|
// // Add menu items to popup menu
|
||||||
popup.add(showItem);
|
// popup.add(showItem);
|
||||||
popup.addSeparator();
|
// popup.addSeparator();
|
||||||
popup.add(exitItem);
|
// popup.add(exitItem);
|
||||||
|
|
||||||
// Create tray icon
|
// // Create tray icon
|
||||||
trayIcon = new TrayIcon(icon, "Stirling-PDF", popup);
|
// trayIcon = new TrayIcon(icon, "Stirling-PDF", popup);
|
||||||
trayIcon.setImageAutoSize(true);
|
// trayIcon.setImageAutoSize(true);
|
||||||
|
|
||||||
// Add double-click behavior
|
// // Add double-click behavior
|
||||||
trayIcon.addActionListener(
|
// trayIcon.addActionListener(
|
||||||
e -> {
|
// e -> {
|
||||||
frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
frame.setState(Frame.NORMAL);
|
// frame.setState(Frame.NORMAL);
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Add tray icon to system tray
|
// // Add tray icon to system tray
|
||||||
systemTray.add(trayIcon);
|
// systemTray.add(trayIcon);
|
||||||
|
|
||||||
// Modify frame behavior to minimize to tray
|
// // Modify frame behavior to minimize to tray
|
||||||
frame.addWindowStateListener(
|
// frame.addWindowStateListener(
|
||||||
new WindowStateListener() {
|
// new WindowStateListener() {
|
||||||
public void windowStateChanged(WindowEvent e) {
|
// public void windowStateChanged(WindowEvent e) {
|
||||||
if (e.getNewState() == Frame.ICONIFIED) {
|
// if (e.getNewState() == Frame.ICONIFIED) {
|
||||||
frame.setVisible(false);
|
// frame.setVisible(false);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
} catch (AWTException e) {
|
// } catch (AWTException e) {
|
||||||
log.error("Error setting up system tray icon", e);
|
// log.error("Error setting up system tray icon", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void loadIcon() {
|
// private void loadIcon() {
|
||||||
try {
|
// try {
|
||||||
Image icon = null;
|
// Image icon = null;
|
||||||
String[] iconPaths = {"/static/favicon.ico"};
|
// String[] iconPaths = {"/static/favicon.ico"};
|
||||||
|
|
||||||
for (String path : iconPaths) {
|
// for (String path : iconPaths) {
|
||||||
if (icon != null) break;
|
// if (icon != null) break;
|
||||||
try {
|
// try {
|
||||||
try (InputStream is = getClass().getResourceAsStream(path)) {
|
// try (InputStream is = getClass().getResourceAsStream(path)) {
|
||||||
if (is != null) {
|
// if (is != null) {
|
||||||
icon = ImageIO.read(is);
|
// icon = ImageIO.read(is);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.debug("Could not load icon from " + path, e);
|
// log.debug("Could not load icon from " + path, e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (icon != null) {
|
// if (icon != null) {
|
||||||
frame.setIconImage(icon);
|
// frame.setIconImage(icon);
|
||||||
setupTrayIcon(icon);
|
// setupTrayIcon(icon);
|
||||||
} else {
|
// } else {
|
||||||
log.warn("Could not load icon from any source");
|
// log.warn("Could not load icon from any source");
|
||||||
}
|
// }
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("Error loading icon", e);
|
// log.error("Error loading icon", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@PreDestroy
|
// @PreDestroy
|
||||||
public void cleanup() {
|
// public void cleanup() {
|
||||||
if (browser != null) browser.close(true);
|
// if (browser != null) browser.close(true);
|
||||||
if (client != null) client.dispose();
|
// if (client != null) client.dispose();
|
||||||
if (cefApp != null) cefApp.dispose();
|
// if (cefApp != null) cefApp.dispose();
|
||||||
if (loadingWindow != null) loadingWindow.dispose();
|
// if (loadingWindow != null) loadingWindow.dispose();
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static void forceInitializeUI() {
|
// public static void forceInitializeUI() {
|
||||||
try {
|
// try {
|
||||||
if (loadingWindow != null) {
|
// if (loadingWindow != null) {
|
||||||
log.info("Forcing start of UI initialization sequence");
|
// log.info("Forcing start of UI initialization sequence");
|
||||||
|
|
||||||
// Close loading window first
|
// // Close loading window first
|
||||||
loadingWindow.setVisible(false);
|
// loadingWindow.setVisible(false);
|
||||||
loadingWindow.dispose();
|
// loadingWindow.dispose();
|
||||||
loadingWindow = null;
|
// loadingWindow = null;
|
||||||
log.info("Loading window disposed");
|
// log.info("Loading window disposed");
|
||||||
|
|
||||||
// Then setup the main frame
|
// // Then setup the main frame
|
||||||
frame.setVisible(false);
|
// frame.setVisible(false);
|
||||||
frame.dispose();
|
// frame.dispose();
|
||||||
frame.setOpacity(1.0f);
|
// frame.setOpacity(1.0f);
|
||||||
frame.setUndecorated(false);
|
// frame.setUndecorated(false);
|
||||||
frame.pack();
|
// frame.pack();
|
||||||
frame.setSize(UIScaling.scaleWidth(1280), UIScaling.scaleHeight(800));
|
// frame.setSize(UIScaling.scaleWidth(1280), UIScaling.scaleHeight(800));
|
||||||
frame.setLocationRelativeTo(null);
|
// frame.setLocationRelativeTo(null);
|
||||||
log.debug("Frame reconfigured");
|
// log.debug("Frame reconfigured");
|
||||||
|
|
||||||
// Show the main frame
|
// // Show the main frame
|
||||||
frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
frame.requestFocus();
|
// frame.requestFocus();
|
||||||
frame.toFront();
|
// frame.toFront();
|
||||||
log.info("Main frame displayed and focused");
|
// log.info("Main frame displayed and focused");
|
||||||
|
|
||||||
// Focus the browser component if available
|
// // Focus the browser component if available
|
||||||
if (browser != null) {
|
// if (browser != null) {
|
||||||
Timer focusTimer =
|
// Timer focusTimer =
|
||||||
new Timer(
|
// new Timer(
|
||||||
100,
|
// 100,
|
||||||
e -> {
|
// e -> {
|
||||||
try {
|
// try {
|
||||||
browser.getUIComponent().requestFocus();
|
// browser.getUIComponent().requestFocus();
|
||||||
log.info("Browser component focused");
|
// log.info("Browser component focused");
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
log.error(
|
// log.error(
|
||||||
"Error focusing browser during force ui"
|
// "Error focusing browser during force ui"
|
||||||
+ " initialization.",
|
// + " initialization.",
|
||||||
ex);
|
// ex);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
focusTimer.setRepeats(false);
|
// focusTimer.setRepeats(false);
|
||||||
focusTimer.start();
|
// focusTimer.start();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("Error during Forced UI initialization.", e);
|
// log.error("Error during Forced UI initialization.", e);
|
||||||
// Attempt cleanup on error
|
// // Attempt cleanup on error
|
||||||
if (loadingWindow != null) {
|
// if (loadingWindow != null) {
|
||||||
loadingWindow.dispose();
|
// loadingWindow.dispose();
|
||||||
loadingWindow = null;
|
// loadingWindow = null;
|
||||||
}
|
// }
|
||||||
if (frame != null) {
|
// if (frame != null) {
|
||||||
frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
frame.setOpacity(1.0f);
|
// frame.setOpacity(1.0f);
|
||||||
frame.setUndecorated(false);
|
// frame.setUndecorated(false);
|
||||||
frame.requestFocus();
|
// frame.requestFocus();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user