diff --git a/app/ant/processing/app/Schema.java b/app/ant/processing/app/Schema.java new file mode 100644 index 000000000..6e1e92ef2 --- /dev/null +++ b/app/ant/processing/app/Schema.java @@ -0,0 +1,9 @@ +package processing.app; + +import processing.app.ui.Editor; + +public class Schema { + public static Editor handleSchema(String input, Base base) { + return null; + } +} diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 630da2146..a5b3ac7c0 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -44,7 +44,6 @@ import processing.app.ui.Toolkit; import processing.core.*; import processing.data.StringList; - /** * The base class for the main processing application. * Primary role of this class is for platform identification and @@ -1367,6 +1366,11 @@ public class Base { * @param schemeUri the full URI, including pde:// */ public Editor handleScheme(String schemeUri) { + var result = Schema.handleSchema(schemeUri, this); + if (result != null) { + return result; + } + String location = schemeUri.substring(6); if (location.length() > 0) { // if it leads with a slash, then it's a file url diff --git a/app/src/processing/app/Schema.kt b/app/src/processing/app/Schema.kt new file mode 100644 index 000000000..153eeec4b --- /dev/null +++ b/app/src/processing/app/Schema.kt @@ -0,0 +1,65 @@ +package processing.app + +import processing.app.ui.Editor +import java.io.File +import java.net.URI +import java.net.URLDecoder +import java.nio.charset.StandardCharsets + + +class Schema { + companion object{ + private var base: Base? = null + @JvmStatic + fun handleSchema(input: String, base: Base): Editor?{ + this.base = base + val uri = URI.create(input) + return when (uri.host) { + null -> handleLocalFile(uri.path) + "sketch" -> handleSketch(uri) + "preferences" -> handlePreferences(uri) + else -> handleRemoteFile(uri) + } + } + private fun handleLocalFile(input: String): Editor?{ + return base?.handleOpen(input) + } + private fun handleSketch(uri: URI): Editor?{ + val paths = uri.path.split("/") + return when(paths.getOrNull(1)){ + "base64" -> handleSketchBase64(uri) + else -> null + } + } + private fun handleSketchBase64(uri: URI): Editor?{ + val tempSketchFolder = SketchName.nextFolder(Base.untitledFolder); + tempSketchFolder.mkdirs() + val tempSketchFile = File(tempSketchFolder, "${tempSketchFolder.name}.pde") + val sketchB64 = uri.path.replace("/base64/", "") + val sketch = java.util.Base64.getDecoder().decode(sketchB64) + tempSketchFile.writeBytes(sketch) + val editor = base?.handleOpenUntitled(tempSketchFile.absolutePath) + return editor + } + + private fun handlePreferences(uri: URI): Editor?{ + val options = uri.query?.split("&") + ?.map { it.split("=") } + ?.associate { + URLDecoder.decode(it[0], StandardCharsets.UTF_8) to + URLDecoder.decode(it[1], StandardCharsets.UTF_8) + } + ?: emptyMap() + for ((key, value) in options){ + Preferences.set(key, value) + } + Preferences.save() + + return null + } + + private fun handleRemoteFile(uri: URI): Editor?{ + return null + } + } +} \ No newline at end of file