Browse Source

Added support for dark theme in loading screen.

pull/75/head
CalDescent 3 years ago
parent
commit
631a253bcc
  1. 36
      src/main/java/org/qortal/api/resource/RenderResource.java
  2. 10
      src/main/java/org/qortal/arbitrary/ArbitraryDataRenderer.java
  3. 23
      src/main/resources/loading/index.html

36
src/main/java/org/qortal/api/resource/RenderResource.java

@ -138,34 +138,38 @@ public class RenderResource {
@GET @GET
@Path("/signature/{signature}") @Path("/signature/{signature}")
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public HttpServletResponse getIndexBySignature(@PathParam("signature") String signature) { public HttpServletResponse getIndexBySignature(@PathParam("signature") String signature,
@QueryParam("theme") String theme) {
Security.requirePriorAuthorization(request, signature, Service.WEBSITE, null); Security.requirePriorAuthorization(request, signature, Service.WEBSITE, null);
return this.get(signature, ResourceIdType.SIGNATURE, null, "/", null, "/render/signature", true, true); return this.get(signature, ResourceIdType.SIGNATURE, null, "/", null, "/render/signature", true, true, theme);
} }
@GET @GET
@Path("/signature/{signature}/{path:.*}") @Path("/signature/{signature}/{path:.*}")
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public HttpServletResponse getPathBySignature(@PathParam("signature") String signature, @PathParam("path") String inPath) { public HttpServletResponse getPathBySignature(@PathParam("signature") String signature, @PathParam("path") String inPath,
@QueryParam("theme") String theme) {
Security.requirePriorAuthorization(request, signature, Service.WEBSITE, null); Security.requirePriorAuthorization(request, signature, Service.WEBSITE, null);
return this.get(signature, ResourceIdType.SIGNATURE, null, inPath,null, "/render/signature", true, true); return this.get(signature, ResourceIdType.SIGNATURE, null, inPath,null, "/render/signature", true, true, theme);
} }
@GET @GET
@Path("/hash/{hash}") @Path("/hash/{hash}")
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public HttpServletResponse getIndexByHash(@PathParam("hash") String hash58, @QueryParam("secret") String secret58) { public HttpServletResponse getIndexByHash(@PathParam("hash") String hash58, @QueryParam("secret") String secret58,
@QueryParam("theme") String theme) {
Security.requirePriorAuthorization(request, hash58, Service.WEBSITE, null); Security.requirePriorAuthorization(request, hash58, Service.WEBSITE, null);
return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, "/", secret58, "/render/hash", true, false); return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, "/", secret58, "/render/hash", true, false, theme);
} }
@GET @GET
@Path("/hash/{hash}/{path:.*}") @Path("/hash/{hash}/{path:.*}")
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public HttpServletResponse getPathByHash(@PathParam("hash") String hash58, @PathParam("path") String inPath, public HttpServletResponse getPathByHash(@PathParam("hash") String hash58, @PathParam("path") String inPath,
@QueryParam("secret") String secret58) { @QueryParam("secret") String secret58,
@QueryParam("theme") String theme) {
Security.requirePriorAuthorization(request, hash58, Service.WEBSITE, null); Security.requirePriorAuthorization(request, hash58, Service.WEBSITE, null);
return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, inPath, secret58, "/render/hash", true, false); return this.get(hash58, ResourceIdType.FILE_HASH, Service.WEBSITE, inPath, secret58, "/render/hash", true, false, theme);
} }
@GET @GET
@ -173,29 +177,35 @@ public class RenderResource {
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public HttpServletResponse getPathByName(@PathParam("service") Service service, public HttpServletResponse getPathByName(@PathParam("service") Service service,
@PathParam("name") String name, @PathParam("name") String name,
@PathParam("path") String inPath) { @PathParam("path") String inPath,
@QueryParam("theme") String theme) {
Security.requirePriorAuthorization(request, name, service, null); Security.requirePriorAuthorization(request, name, service, null);
String prefix = String.format("/render/%s", service); String prefix = String.format("/render/%s", service);
return this.get(name, ResourceIdType.NAME, service, inPath, null, prefix, true, true); return this.get(name, ResourceIdType.NAME, service, inPath, null, prefix, true, true, theme);
} }
@GET @GET
@Path("{service}/{name}") @Path("{service}/{name}")
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public HttpServletResponse getIndexByName(@PathParam("service") Service service, public HttpServletResponse getIndexByName(@PathParam("service") Service service,
@PathParam("name") String name) { @PathParam("name") String name,
@QueryParam("theme") String theme) {
Security.requirePriorAuthorization(request, name, service, null); Security.requirePriorAuthorization(request, name, service, null);
String prefix = String.format("/render/%s", service); String prefix = String.format("/render/%s", service);
return this.get(name, ResourceIdType.NAME, service, "/", null, prefix, true, true); return this.get(name, ResourceIdType.NAME, service, "/", null, prefix, true, true, theme);
} }
private HttpServletResponse get(String resourceId, ResourceIdType resourceIdType, Service service, String inPath, private HttpServletResponse get(String resourceId, ResourceIdType resourceIdType, Service service, String inPath,
String secret58, String prefix, boolean usePrefix, boolean async) { String secret58, String prefix, boolean usePrefix, boolean async, String theme) {
ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath, ArbitraryDataRenderer renderer = new ArbitraryDataRenderer(resourceId, resourceIdType, service, inPath,
secret58, prefix, usePrefix, async, request, response, context); secret58, prefix, usePrefix, async, request, response, context);
if (theme != null) {
renderer.setTheme(theme);
}
return renderer.render(); return renderer.render();
} }

10
src/main/java/org/qortal/arbitrary/ArbitraryDataRenderer.java

@ -34,6 +34,7 @@ public class ArbitraryDataRenderer {
private final String resourceId; private final String resourceId;
private final ResourceIdType resourceIdType; private final ResourceIdType resourceIdType;
private final Service service; private final Service service;
private String theme = "light";
private String inPath; private String inPath;
private final String secret58; private final String secret58;
private final String prefix; private final String prefix;
@ -77,7 +78,7 @@ public class ArbitraryDataRenderer {
// If async is requested, show a loading screen whilst build is in progress // If async is requested, show a loading screen whilst build is in progress
if (async) { if (async) {
arbitraryDataReader.loadAsynchronously(false, 10); arbitraryDataReader.loadAsynchronously(false, 10);
return this.getLoadingResponse(service, resourceId); return this.getLoadingResponse(service, resourceId, theme);
} }
// Otherwise, loop until we have data // Otherwise, loop until we have data
@ -171,7 +172,7 @@ public class ArbitraryDataRenderer {
return userPath; return userPath;
} }
private HttpServletResponse getLoadingResponse(Service service, String name) { private HttpServletResponse getLoadingResponse(Service service, String name, String theme) {
String responseString = ""; String responseString = "";
URL url = Resources.getResource("loading/index.html"); URL url = Resources.getResource("loading/index.html");
try { try {
@ -180,6 +181,7 @@ public class ArbitraryDataRenderer {
// Replace vars // Replace vars
responseString = responseString.replace("%%SERVICE%%", service.toString()); responseString = responseString.replace("%%SERVICE%%", service.toString());
responseString = responseString.replace("%%NAME%%", name); responseString = responseString.replace("%%NAME%%", name);
responseString = responseString.replace("%%THEME%%", theme);
} catch (IOException e) { } catch (IOException e) {
LOGGER.info("Unable to show loading screen: {}", e.getMessage()); LOGGER.info("Unable to show loading screen: {}", e.getMessage());
@ -210,4 +212,8 @@ public class ArbitraryDataRenderer {
return indexFiles; return indexFiles;
} }
public void setTheme(String theme) {
this.theme = theme;
}
} }

23
src/main/resources/loading/index.html

@ -128,6 +128,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
<canvas id="c"></canvas> <canvas id="c"></canvas>
<!-- partial --> <!-- partial -->
<script> <script>
var theme = "%%THEME%%";
var w = c.width = window.innerWidth, var w = c.width = window.innerWidth,
h = c.height = window.innerHeight, h = c.height = window.innerHeight,
ctx = c.getContext( '2d' ), ctx = c.getContext( '2d' ),
@ -165,7 +167,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
baseRad = Math.PI * 2 / 6; baseRad = Math.PI * 2 / 6;
ctx.fillStyle = 'white'; if (theme === "dark") {
ctx.fillStyle = 'black';
}
else {
ctx.fillStyle = 'white';
}
ctx.fillRect( 0, 0, w, h ); ctx.fillRect( 0, 0, w, h );
function loop() { function loop() {
@ -176,9 +183,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
ctx.globalCompositeOperation = 'source-over'; ctx.globalCompositeOperation = 'source-over';
ctx.shadowBlur = 0; ctx.shadowBlur = 0;
ctx.fillStyle = 'rgba(230,230,230,alp)'.replace( 'alp', opts.repaintAlpha );
ctx.fillRect( 0, 0, w, h ); if (theme === "dark") {
ctx.globalCompositeOperation = 'darker'; ctx.fillStyle = 'rgba(0,0,0,alp)'.replace('alp', opts.repaintAlpha);
ctx.fillRect( 0, 0, w, h );
ctx.globalCompositeOperation = 'lighter';
}
else {
ctx.fillStyle = 'rgba(230,230,230,alp)'.replace('alp', opts.repaintAlpha);
ctx.fillRect( 0, 0, w, h );
ctx.globalCompositeOperation = 'darker';
}
if( lines.length < opts.count && Math.random() < opts.spawnChance ) if( lines.length < opts.count && Math.random() < opts.spawnChance )
lines.push( new Line ); lines.push( new Line );

Loading…
Cancel
Save