Skip to content

Commit f6586da

Browse files
committed
Organize JS scaffolding, add packages via UI
- Put JavaScript into dedicated project folder and use Gradle to copy it into resources to use for new p5.js sketches - First iteration of Compose UI to add packages from npm registry via pnpm
1 parent 799f95a commit f6586da

File tree

12 files changed

+813
-164
lines changed

12 files changed

+813
-164
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ tasks.register("includeProcessingResources"){
429429
"includeJavaMode",
430430
"includeSharedAssets",
431431
"includeProcessingExamples",
432-
"includeProcessingWebsiteExamples",
432+
// "includeProcessingWebsiteExamples",
433433
"includeJavaModeResources",
434434
"renameWindres"
435435
)

app/src/processing/app/Base.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class Base {
100100

101101
/** Only one built-in Mode these days, removing the extra fluff. */
102102
private Mode coreMode;
103+
private Mode p5jsMode;
103104

104105
// TODO can these be Set objects, or are they expected to be in order?
105106
private List<ModeContribution> contribModes;
@@ -755,6 +756,7 @@ public void tallyUpdatesAvailable() {
755756
public List<Mode> getModeList() {
756757
List<Mode> outgoing = new ArrayList<>();
757758
outgoing.add(coreMode);
759+
outgoing.add(p5jsMode);
758760
if (contribModes != null) {
759761
for (ModeContribution contrib : contribModes) {
760762
outgoing.add(contrib.getMode());
@@ -765,19 +767,25 @@ public List<Mode> getModeList() {
765767

766768

767769
void buildCoreModes() {
768-
ModeContribution javaModeContrib =
769-
ModeContribution.load(this, Platform.getContentFile("modes/java"),
770-
getDefaultModeIdentifier());
770+
ModeContribution javaModeContrib = ModeContribution.load(this, Platform.getContentFile("modes/java"), getDefaultModeIdentifier());
771+
ModeContribution p5jsModeContrib = ModeContribution.load(this, Platform.getContentFile("modes/p5js"), "processing.p5js.p5js");
771772
if (javaModeContrib == null) {
772773
Messages.showError("Startup Error",
773-
"Could not load Java Mode, please reinstall Processing.",
774-
new Exception("ModeContribution.load() was null"));
774+
"Could not load Java Mode, please reinstall Processing.",
775+
new Exception("ModeContribution.load() was null"));
775776

776777
} else {
777778
// PDE X calls getModeList() while it's loading, so coreModes must be set
778779
//coreModes = new Mode[] { javaModeContrib.getMode() };
779780
coreMode = javaModeContrib.getMode();
780781
}
782+
if (p5jsModeContrib == null) {
783+
Messages.showError("Startup Error",
784+
"Could not load p5.js Mode, please reinstall Processing.",
785+
new Exception("ModeContribution.load() was null"));
786+
} else {
787+
p5jsMode = p5jsModeContrib.getMode();
788+
}
781789
}
782790

783791

p5js/build.gradle.kts

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
plugins {
2-
kotlin("jvm") version "2.0.20"
2+
kotlin("jvm") version libs.versions.kotlin
33
kotlin("plugin.serialization") version "1.9.0"
4-
}
54

6-
group = "org.processing"
7-
version = "1.0-SNAPSHOT"
5+
// TODO Unclear whether the whole Compose dependency is necessary
6+
alias(libs.plugins.compose.compiler)
7+
alias(libs.plugins.jetbrainsCompose)
8+
}
89

910
repositories {
1011
mavenCentral()
@@ -13,62 +14,49 @@ repositories {
1314
}
1415

1516
dependencies {
16-
// compileOnly(files("/Applications/Processing.app/Contents/Java/pde.jar/**/"))
17+
compileOnly(project(":app"))
1718
implementation(project(":core"))
18-
implementation(project(":app"))
1919

2020
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
2121
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
2222

23-
testImplementation(kotlin("test"))
23+
implementation(compose.runtime)
24+
implementation(compose.foundation)
25+
implementation(compose.material)
26+
implementation(compose.ui)
27+
implementation(compose.components.resources)
28+
implementation(compose.components.uiToolingPreview)
2429
}
2530

26-
project(":app").tasks.named("run").configure {
27-
dependsOn(tasks.named("installLibrary"))
28-
}
29-
tasks.create<Copy>("copyJars") {
30-
group = "processing"
31-
dependsOn(tasks.jar)
32-
from(layout.buildDirectory.dir("libs")){
33-
include("**/*.jar")
31+
tasks.register<Copy>("createMode") {
32+
dependsOn("jar")
33+
into(layout.buildDirectory.dir("mode"))
34+
// TODO Why is there a duplicate in the first place?
35+
duplicatesStrategy = DuplicatesStrategy.WARN
36+
37+
from(layout.projectDirectory.dir("library")) {
38+
include ("**")
39+
}
40+
41+
from(layout.projectDirectory) {
42+
include("js/**")
43+
}
44+
45+
from(configurations.runtimeClasspath) {
46+
into("mode")
47+
}
48+
49+
from(tasks.jar) {
50+
into("mode")
3451
}
35-
from(configurations.compileClasspath)
36-
into(layout.buildDirectory.dir("library/mode"))
37-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
38-
}
39-
tasks.create<Copy>("createLibrary") {
40-
group = "processing"
41-
from("library")
42-
into(layout.buildDirectory.dir("library"))
43-
}
44-
tasks.create<Copy>("installLibrary") {
45-
group = "processing"
46-
dependsOn(tasks.named("createLibrary"))
47-
dependsOn(tasks.named("copyJars"))
48-
from(layout.buildDirectory.dir("library"))
49-
into("${System.getProperty("user.home")}/sketchbook/modes/p5js")
50-
}
51-
//tasks.register<JavaExec>("runProcessing") {
52-
// dependsOn(tasks.named("installLibrary"))
53-
// group = "processing"
54-
// classpath = files(fileTree("/Applications/Processing.app/Contents/Java/"){
55-
// include("*.jar")
56-
// })
57-
// mainClass.set("processing.app.Base") // Your main class
58-
//
59-
// // Optional: Add arguments if needed
60-
// args = listOf("")
61-
//
62-
// // Optional: Add JVM arguments if needed
63-
// jvmArgs = listOf("-Xmx2g")
64-
//}
65-
tasks.jar {
66-
archiveVersion.set("")
67-
archiveBaseName.set("p5js")
6852
}
69-
tasks.test {
70-
useJUnitPlatform()
53+
54+
tasks.register<Copy>("includeMode") {
55+
dependsOn("createMode")
56+
from(tasks.named("createMode"))
57+
into(project(":app").layout.buildDirectory.dir("resources-bundled/common/modes/p5js"))
7158
}
72-
kotlin {
73-
jvmToolchain(17)
59+
60+
project(":app").tasks.named("includeProcessingResources").configure {
61+
dependsOn(tasks.named("includeMode"))
7462
}

p5js/js/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.1/p5.js"></script>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.1/addons/p5.sound.min.js"></script>
6+
<meta charset="utf-8" />
7+
<style>
8+
html, body {
9+
margin: 0;
10+
padding: 0;
11+
}
12+
canvas {
13+
display: block;
14+
}
15+
</style>
16+
</head>
17+
18+
<body>
19+
<script src="./renderer.js"></script>
20+
<script src="${packageJson.sketch}"></script>
21+
</body>
22+
</html>

p5js/js/main.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const path = require('node:path');
2+
const { app, BrowserWindow, globalShortcut, ipcMain } = require('electron');
3+
4+
const createWindow = () => {
5+
const win = new BrowserWindow({
6+
width: 400,
7+
height: 400,
8+
useContentSize: true,
9+
autoHideMenuBar: true,
10+
alwaysOnTop: true,
11+
webPreferences: {
12+
nodeIntegration: true,
13+
preload: path.join(__dirname, "preload.js")
14+
}
15+
});
16+
17+
win.loadFile('index.html');
18+
19+
// Register the 'Escape' key shortcut
20+
globalShortcut.register('Escape', () => {
21+
win.close();
22+
});
23+
24+
// Unregister the shortcut when window is closed
25+
win.on('closed', () => {
26+
globalShortcut.unregister('Escape');
27+
});
28+
}
29+
30+
app.on('window-all-closed', () => {
31+
// Unregister all shortcuts when app is closing
32+
globalShortcut.unregisterAll();
33+
app.quit();
34+
});
35+
36+
app.whenReady().then(() => {
37+
ipcMain.on("send-message", (event, message) => {
38+
console.log(message);
39+
});
40+
createWindow();
41+
});

p5js/js/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "p5js-mode-scaffold",
3+
"version": "0.1.0",
4+
"main": "main.js",
5+
"devDependencies": {
6+
"electron": "^37.4.0"
7+
}
8+
}

0 commit comments

Comments
 (0)