Skip to content

Commit 99ee838

Browse files
committed
WIP: fix bugs and add TypeScript example
1 parent 9ad1dfb commit 99ee838

27 files changed

+13483
-76
lines changed

p5js/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919

2020
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
2121
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
22+
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.12.0")
2223

2324
implementation(compose.runtime)
2425
implementation(compose.foundation)
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const createWindow = () => {
1515
}
1616
});
1717

18-
win.loadFile('index.html');
18+
win.loadFile('electron/index.html');
1919

2020
// Register the 'Escape' key shortcut
2121
globalShortcut.register('Escape', () => {
@@ -26,6 +26,8 @@ const createWindow = () => {
2626
win.on('closed', () => {
2727
globalShortcut.unregister('Escape');
2828
});
29+
30+
return win;
2931
}
3032

3133
app.on('window-all-closed', () => {
@@ -35,8 +37,13 @@ app.on('window-all-closed', () => {
3537
});
3638

3739
app.whenReady().then(() => {
40+
const win = createWindow();
41+
3842
ipcMain.on("send-message", (event, message) => {
3943
console.log(message);
4044
});
41-
createWindow();
45+
46+
ipcMain.on("resize", (event, {width, height}) => {
47+
win.setSize(width, height);
48+
});
4249
});
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const { ipcRenderer } = require("electron");
22

33
window.pde = {
4-
sendMessage: (message) => ipcRenderer.send("send-message", message)
4+
sendMessage: (message) => ipcRenderer.send("send-message", message),
5+
resize: (dimensions) => ipcRenderer.send("resize", dimensions)
56
};
67

78
// Force-disable security warning

p5js/js/electron/resizer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const targetNode = document.querySelector("body");
2+
const config = { childList: true };
3+
4+
const observer = new MutationObserver((mutationList) => {
5+
// Once p5 is ready, it adds a <main> node containing the drawing canvas
6+
const p5Ready = mutationList.filter(
7+
mutation => mutation.addedNodes[0]?.nodeName === "MAIN"
8+
).length > 0;
9+
if (p5Ready) {
10+
const { width, height } = document.querySelector("canvas");
11+
pde.resize({
12+
width,
13+
height
14+
});
15+
}
16+
});
17+
18+
observer.observe(targetNode, config);
19+

p5js/js/electron/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
html, body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
canvas {
6+
display: block;
7+
}

p5js/js/index.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

p5js/js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "p5js-mode-scaffold",
2+
"name": "sketch",
33
"version": "0.1.0",
4-
"main": "main.js",
4+
"main": "electron/main.js",
55
"build": {
66
"appId": "org.processing.user.p5mode",
77
"electronLanguages": [],
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)