Skip to content

Commit

Permalink
add useDefaultHtmlIndex and logoPath
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Nov 4, 2023
1 parent 4bf4eb1 commit 4962ce1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Update teavm to 0.10.0-dev-1
- Update libgdx to 1.12.1
- Remove obfuscate from build config. Use TeaVMTool.
- Add useDefaultHtmlIndex and logoPath config option.

[1.0.0-b7]
- Remove jParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class TeaBuildConfiguration {
public String htmlTitle = "gdx-teavm";
public int htmlWidth = 800;
public int htmlHeight = 600;
/**
* If the logo is shown while the application is loading.
*/

/** True to use the default html index. False will stop overwriting html file. */
public boolean useDefaultHtmlIndex = true;

/** If the logo is shown while the application is loading. Requires showLoadingLogo true. */
public boolean showLoadingLogo = true;

/**
* Logo asset path.
*/
public String logo = "startup-logo.png";
/** Logo asset path. Requires showLoadingLogo true. */
public String logoPath = "startup-logo.png";

public String getHtmlTitle() {
return htmlTitle;
Expand All @@ -61,6 +61,10 @@ public boolean isShowLoadingLogo() {
return showLoadingLogo;
}

public boolean shouldUseDefaultHtmlIndex() {
return useDefaultHtmlIndex;
}

public String getMainClass() {
return mainClass;
}
Expand Down Expand Up @@ -126,6 +130,6 @@ public boolean acceptClasspath(URL url) {
}

public String getLogoPath() {
return logo;
return logoPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -533,36 +533,42 @@ public static void configAssets(TeaClassLoader classLoader, TeaBuildConfiguratio
webappAssetsFiles.add(webappName);
TeaBuilder.logHeader("COPYING ASSETS");

AssetsCopy.copy(classLoader, webappAssetsFiles, new ArrayList<>(), null, webappDirectory, false);
TeaBuilder.log("");
boolean shouldUseDefaultHtmlIndex = configuration.shouldUseDefaultHtmlIndex();
if(shouldUseDefaultHtmlIndex) {
AssetsCopy.copy(classLoader, webappAssetsFiles, new ArrayList<>(), null, webappDirectory, false);
TeaBuilder.log("");
}

String scriptsOutputPath = webappDirectory + File.separator + webappName;
String assetsOutputPath = scriptsOutputPath + File.separator + "assets";

File indexFile = new File(scriptsOutputPath + File.separator + "index.html");
FileHandle handler = new FileHandle(indexFile);
String indexHtmlStr = handler.readString();

String logo = configuration.getLogoPath();
String htmlLogo = "assets/" + logo;
boolean showLoadingLogo = configuration.isShowLoadingLogo();

indexHtmlStr = indexHtmlStr.replace("%TITLE%", configuration.getHtmlTitle());
indexHtmlStr = indexHtmlStr.replace("%WIDTH%", configuration.getHtmlWidth());
indexHtmlStr = indexHtmlStr.replace("%HEIGHT%", configuration.getHtmlHeight());
indexHtmlStr = indexHtmlStr.replace("%ARGS%", configuration.getMainClassArgs());
indexHtmlStr = indexHtmlStr.replace(
"%LOGO%", showLoadingLogo ? "<img id=\"progress-img\" src=\"" + htmlLogo + "\">" : ""
);

handler.writeString(indexHtmlStr, false);

AssetFilter filter = configuration.assetFilter();
ArrayList<File> assetsPaths = new ArrayList<>();
ArrayList<String> classPathAssetsFiles = new ArrayList<>();
assetsDefaultClasspath(classPathAssetsFiles);
if(showLoadingLogo) {
classPathAssetsFiles.add(logo);

if(shouldUseDefaultHtmlIndex) {
File indexFile = new File(scriptsOutputPath + File.separator + "index.html");
FileHandle handler = new FileHandle(indexFile);
String indexHtmlStr = handler.readString();

String logo = configuration.getLogoPath();
String htmlLogo = "assets/" + logo;
boolean showLoadingLogo = configuration.isShowLoadingLogo();

indexHtmlStr = indexHtmlStr.replace("%TITLE%", configuration.getHtmlTitle());
indexHtmlStr = indexHtmlStr.replace("%WIDTH%", configuration.getHtmlWidth());
indexHtmlStr = indexHtmlStr.replace("%HEIGHT%", configuration.getHtmlHeight());
indexHtmlStr = indexHtmlStr.replace("%ARGS%", configuration.getMainClassArgs());
indexHtmlStr = indexHtmlStr.replace(
"%LOGO%", showLoadingLogo ? "<img id=\"progress-img\" src=\"" + htmlLogo + "\">" : ""
);

handler.writeString(indexHtmlStr, false);

if(showLoadingLogo) {
classPathAssetsFiles.add(logo);
}
}
ArrayList<String> additionalAssetClasspath = configuration.getAdditionalAssetClasspath();
classPathAssetsFiles.addAll(additionalAssetClasspath);
Expand Down
3 changes: 1 addition & 2 deletions examples/core/teavm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ tasks.register("core-build", JavaExec) {
setClasspath(sourceSets.main.runtimeClasspath)
}
tasks.register("core-run-teavm") {
dependsOn(["clean", "core-build", "jettyRun"])
dependsOn(["core-build", "jettyRun"])
setGroup("examples-teavm")
setDescription("Run Test Demo example")

tasks.findByName("core-build")?.mustRunAfter("clean")
tasks.findByName("jettyRun")?.mustRunAfter("core-build")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void main(String[] args) throws IOException {
TeaBuildConfiguration teaBuildConfiguration = new TeaBuildConfiguration();
teaBuildConfiguration.assetsPath.add(new File("../desktop/assets"));
teaBuildConfiguration.webappPath = new File("build/dist").getCanonicalPath();
teaBuildConfiguration.logoPath = "logo.png";

TeaVMTool tool = TeaBuilder.config(teaBuildConfiguration);
tool.setMainClass(TeaVMTestLauncher.class.getName());
Expand Down
Binary file added examples/core/teavm/src/main/resources/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4962ce1

Please sign in to comment.