2023-01-27 19:23:40 +01:00
|
|
|
package stirling.software.SPDF;
|
|
|
|
|
2023-07-04 22:45:35 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
2023-06-25 10:16:32 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2023-01-27 19:23:40 +01:00
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
2023-06-25 10:16:32 +02:00
|
|
|
import org.springframework.core.env.Environment;
|
2023-07-02 19:20:23 +02:00
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
2023-06-10 16:05:38 +02:00
|
|
|
|
|
|
|
import jakarta.annotation.PostConstruct;
|
2023-07-04 22:45:35 +02:00
|
|
|
import stirling.software.SPDF.utils.GeneralUtils;
|
2023-06-10 16:05:38 +02:00
|
|
|
|
2023-01-27 19:23:40 +01:00
|
|
|
@SpringBootApplication
|
2023-07-09 01:05:33 +02:00
|
|
|
@EnableScheduling
|
2023-01-27 19:23:40 +01:00
|
|
|
public class SPdfApplication {
|
2023-06-10 16:05:38 +02:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private Environment env;
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
String port = env.getProperty("local.server.port");
|
|
|
|
if(port == null || port.length() == 0) {
|
|
|
|
port="8080";
|
|
|
|
}
|
|
|
|
String url = "http://localhost:" + port;
|
|
|
|
|
|
|
|
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-02-11 15:27:15 +01:00
|
|
|
public static void main(String[] args) {
|
2023-04-22 13:51:01 +02:00
|
|
|
SpringApplication.run(SPdfApplication.class, args);
|
2023-06-10 16:05:38 +02:00
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2023-07-04 22:45:35 +02:00
|
|
|
|
|
|
|
GeneralUtils.createDir("customFiles/static/");
|
|
|
|
GeneralUtils.createDir("customFiles/templates/");
|
|
|
|
GeneralUtils.createDir("config");
|
2023-06-10 16:05:38 +02:00
|
|
|
System.out.println("Stirling-PDF Started.");
|
|
|
|
|
|
|
|
String port = System.getProperty("local.server.port");
|
|
|
|
if(port == null || port.length() == 0) {
|
|
|
|
port="8080";
|
|
|
|
}
|
|
|
|
String url = "http://localhost:" + port;
|
|
|
|
System.out.println("Navigate to " + url);
|
2023-02-11 15:27:15 +01:00
|
|
|
}
|
2023-06-10 16:05:38 +02:00
|
|
|
|
|
|
|
|
2023-04-01 22:02:54 +02:00
|
|
|
}
|