Skip to content

Commit

Permalink
fix: Cheerpj improved loading
Browse files Browse the repository at this point in the history
Added support for loader directive in package json jdeploy.cheerpj.loader
  • Loading branch information
shannah committed Jan 27, 2024
1 parent 3b02355 commit 06e886f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class Params {
private File appJar;
private File outputDir;

private String cheerpjLoader = "https://cjrtnc.leaningtech.com/3.0rc2/cj3loader.js";

public File getOutputDir() {
return outputDir;
}
Expand Down Expand Up @@ -59,6 +61,15 @@ public Params setIconFile(File iconFile) {
this.iconFile = iconFile;
return this;
}

public Params setCheerpjLoader(String cheerpjLoader) {
this.cheerpjLoader = cheerpjLoader;
return this;
}

public String getCheerpjLoader() {
return cheerpjLoader;
}
}
public void build(Params params) throws IOException {
String mainClass = extractMainClass(params.getAppJar());
Expand All @@ -67,6 +78,7 @@ public void build(Params params) throws IOException {
this.getClass().getResourceAsStream("/ca/weblite/jdeploy/cheerpj/index.html")
);

indexHtml = indexHtml.replace("{{ cheerpjLoader }}", params.getCheerpjLoader());
indexHtml = indexHtml.replace("{{ mainClass }}", mainClass);
indexHtml = indexHtml.replace("{{ classPath }}", classPath);
indexHtml = indexHtml.replace("{{ appName }}", params.getAppName());
Expand Down
17 changes: 17 additions & 0 deletions cli/src/main/java/ca/weblite/jdeploy/services/CheerpjService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public class CheerpjService extends BaseService {
private BuildCheerpjAppService buildCheerpjAppService;

private static final String DEFAULT_CHEERPJ_LOADER = "https://cjrtnc.leaningtech.com/3.0rc2/cj3loader.js";

public CheerpjService(File packageJSONFile, JSONObject packageJSON) throws IOException {
super(packageJSONFile, packageJSON);
buildCheerpjAppService = new BuildCheerpjAppService();
Expand All @@ -34,6 +36,7 @@ private void run() throws IOException {
File dest = this.getDestDirectory();
buildCheerpjAppService.build(
new BuildCheerpjAppService.Params()
.setCheerpjLoader(getCheerpjLoader(DEFAULT_CHEERPJ_LOADER))
.setAppName(getAppName())
.setAppJar(mainJar)
.setOutputDir(dest)
Expand Down Expand Up @@ -108,6 +111,20 @@ private JSONObject getGithubPagesConfig() {
return config;
}

private JSONObject getCheerpjObject() {
if (!isEnabled()) {
return new JSONObject();
}
return getJDeployObject().getJSONObject("cheerpj");
}

private String getCheerpjLoader(String defaultValue) {
if (!getCheerpjObject().has("loader")) {
return defaultValue;
}
return getCheerpjObject().getString("loader");
}

private String getCurrentTag() throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("git", "describe", "--tags", "--exact-match");
Expand Down
15 changes: 11 additions & 4 deletions cli/src/main/resources/ca/weblite/jdeploy/cheerpj/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

<title>{{ title }}</title>

<script src="https://cjrtnc.leaningtech.com/3_20230915_194/cj3loader.js"></script>
<script src="{{ cheerpjLoader }}"></script>

<style>
html, body { margin: 0; height: 100%; }
#cheerpjDisplay {display: none !important;}
#cheerpjDisplay {width: 100%; height:100%; background-color: transparent}
#cheerpjDisplay.finished-loading { display: block !important; }
</style>
<style>
Expand Down Expand Up @@ -371,7 +371,7 @@
setProgress(10);
window.cj1 = await cheerpjInit();
setProgress(50);
window.cj2 = await cheerpjCreateDisplay(800, 600);
window.cj2 = await cheerpjCreateDisplay(window.innerWidth, window.innerHeight);
setProgress(75);
setLabel2("Preparing application components...");
const cj = await cheerpjRunLibrary(prefixClassPath(getClassPathPrefix(), "{{ classPath }}"));
Expand All @@ -380,7 +380,14 @@
async function onWindowResize() {
document.getElementById("cheerpjDisplay").style.height = '100%';
document.getElementById("cheerpjDisplay").style.width = '100%';
await CheerpjSwingUtils.onResize();
while (true) {
try {
await CheerpjSwingUtils.onResize();
break;
} catch (e) {
console.log(e);
}
}
}
window.addEventListener("resize", onWindowResize);
setProgress(90);
Expand Down

0 comments on commit 06e886f

Please sign in to comment.