2023-07-12 01:17:44 +02:00
|
|
|
package stirling.software.SPDF;
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
2023-08-26 13:27:52 +02:00
|
|
|
import java.util.Collections;
|
2023-07-12 01:17:44 +02:00
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
import org.springframework.core.env.Environment;
|
2023-12-25 21:51:32 +01:00
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
2023-08-27 12:59:08 +02:00
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
import jakarta.annotation.PostConstruct;
|
2023-08-26 18:30:49 +02:00
|
|
|
import stirling.software.SPDF.config.ConfigInitializer;
|
2023-08-27 01:39:22 +02:00
|
|
|
import stirling.software.SPDF.utils.GeneralUtils;
|
2023-08-27 12:59:08 +02:00
|
|
|
|
2023-12-30 20:11:27 +01:00
|
|
|
@SpringBootApplication
|
2023-12-25 21:51:32 +01:00
|
|
|
@EnableScheduling
|
2023-07-12 01:17:44 +02:00
|
|
|
public class SPdfApplication {
|
2023-12-29 19:05:01 +01:00
|
|
|
|
2023-12-30 20:11:27 +01:00
|
|
|
@Autowired private Environment env;
|
2023-07-12 01:17:44 +02:00
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
public void init() {
|
|
|
|
// Check if the BROWSER_OPEN environment variable is set to true
|
|
|
|
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
|
|
|
|
boolean browserOpen = browserOpenEnv != null && browserOpenEnv.equalsIgnoreCase("true");
|
|
|
|
|
|
|
|
if (browserOpen) {
|
|
|
|
try {
|
2023-12-29 19:05:01 +01:00
|
|
|
String url = "http://localhost:" + getPort();
|
2023-07-12 01:17:44 +02:00
|
|
|
|
|
|
|
String os = System.getProperty("os.name").toLowerCase();
|
|
|
|
Runtime rt = Runtime.getRuntime();
|
|
|
|
if (os.contains("win")) {
|
|
|
|
// For Windows
|
|
|
|
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-29 19:05:01 +01:00
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
public static void main(String[] args) {
|
2023-12-30 20:11:27 +01:00
|
|
|
SpringApplication app = new SpringApplication(SPdfApplication.class);
|
|
|
|
app.addInitializers(new ConfigInitializer());
|
|
|
|
if (Files.exists(Paths.get("configs/settings.yml"))) {
|
|
|
|
app.setDefaultProperties(
|
|
|
|
Collections.singletonMap(
|
|
|
|
"spring.config.additional-location", "file:configs/settings.yml"));
|
2023-08-26 13:27:52 +02:00
|
|
|
} else {
|
2023-12-30 20:11:27 +01:00
|
|
|
System.out.println(
|
|
|
|
"External configuration file 'configs/settings.yml' does not exist. Using default configuration and environment configuration instead.");
|
2023-08-26 13:27:52 +02:00
|
|
|
}
|
|
|
|
app.run(args);
|
2023-12-29 19:05:01 +01:00
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
try {
|
2023-12-30 20:11:27 +01:00
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2023-12-29 19:05:01 +01:00
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
GeneralUtils.createDir("customFiles/static/");
|
|
|
|
GeneralUtils.createDir("customFiles/templates/");
|
2023-12-29 19:05:01 +01:00
|
|
|
|
2023-07-12 01:17:44 +02:00
|
|
|
System.out.println("Stirling-PDF Started.");
|
2023-12-29 19:05:01 +01:00
|
|
|
|
|
|
|
String url = "http://localhost:" + getPort();
|
|
|
|
System.out.println("Navigate to " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPort() {
|
2023-07-12 01:17:44 +02:00
|
|
|
String port = System.getProperty("local.server.port");
|
2023-12-29 19:05:01 +01:00
|
|
|
if (port == null || port.isEmpty()) {
|
|
|
|
port = "8080";
|
2023-07-12 01:17:44 +02:00
|
|
|
}
|
2023-12-29 19:05:01 +01:00
|
|
|
return port;
|
2023-07-12 01:17:44 +02:00
|
|
|
}
|
2023-12-29 19:05:01 +01:00
|
|
|
}
|