-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
238 lines (234 loc) · 10.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Plopp</title>
<link rel="icon" type="image/png" href="index.png">
<link rel="apple-touch-icon" href="index.png" sizes="152x152">
<meta name="viewport" content="minimum-scale=1,maximum-scale=1,width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="msapplication-TileImage" content="index.png">
<link rel="stylesheet" href="index.css">
<script type="module" src="vm/squeak.js"></script>
</head>
<body>
<canvas id="sqCanvas" width="800" height="600"></canvas>
<div id="sqSpinner"><div></div></div>
<div id="start" class="overlay">
<b>Click to start Plopp</b><br>
<br>
<img id="logo" src="index.png"><br>
<br>
Note: The initial wait might be quite long.<br>
<br>
Plopp is a Squeak Smalltalk application
(© impara GmbH, Magdeburg 2007).<br>
<br>
The web runtime was created by Vanessa Freudenberg in 2024 using her SqueakJS VM.<br>
</div>
<div id="continue" class="overlay">
<b>Click to continue</b><br>
<br>
<img id="logo" src="index.png"><br>
</div>
<progress id="progress"></progress>
<div id="printerpage">
<img id="printedimage">
</div>
<script src="vm/plopp-mpeg3-plugin.js"></script>
<script src="vm/plopp-b3daccel-plugin.js"></script>
<script src="vm/plopp-b3dengine-plugin.js"></script>
<script src="vm/plopp-opengl.js"></script>
<script src="vm/plopp-socket-plugin.js"></script>
<script>
// TODO:
// [x] - implement primJPEGWriteImage, required for:
// [ ] - photo/wallpaper export
// [x] - printing
// [ ] - ecard sending (?)
// the main reason for requiring a click
// is to allow video/audio to play later
start.onclick = function() {
Squeak.debugFiles = false;
// hide start overlay
start.style.display = "none";
// setup files
setupFiles();
// setup audio/video for MPEG3Plugin
setupAudioVideo();
// emulate unix system calls
Squeak.registerExternalModule('libc.so', unixRuntime());
// run Plopp
SqueakJS.runSqueak("Contents/Resources/plopp.image", sqCanvas, {
appName: "Plopp",
fixedWidth: 800,
fixedHeight: 600,
fullscreen: true,
spinner: sqSpinner,
root: "/Plopp",
templates: { "/Plopp": "." },
});
};
function setupFiles() {
// disable fsck (has trouble with templates)
Squeak.fsck = function() {};
// reload templates if from older version
const root = "squeak-template:/Plopp";
const templates = Squeak.Settings[root];
if (templates && !templates.includes("Contents/Resources")) {
const all = Object.keys(Squeak.Settings);
for (const key of all) {
if (key.startsWith(root)) {
delete Squeak.Settings[key];
}
}
}
// set up progress bar
// if this is a fresh installation there will be 198 reads+writes
// otherwise we will count the files in the user art directory
let count = 0;
const userArt = "/Plopp/user/.Plopp1.2";
if (Squeak.dirList(userArt + "/Paintings")) {
for (const dir of ["Paintings", "Floors", "Wallpapers"]) {
let files = Object.keys(Squeak.dirList(userArt + "/" + dir)).length;
if (dir === "Paintings") files /= 2; // reading frontside only
count += files;
}
}
const progressbar = document.getElementById("progress");
progressbar.max = (count || 198) + 5; // +5 so it feels faster
let progressValue = 0;
const showProgress = function(path) {
progressbar.value = ++progressValue;
progress.style.display = "block";
};
const { fileGet, filePut } = Squeak;
Squeak.fileGet = function(path, ...args) {
showProgress(path);
return fileGet.call(Squeak, path, ...args);
}
Squeak.filePut = function(path, ...args) {
showProgress(path);
return filePut.call(Squeak, path, ...args);
}
// hide progress bar when intro video starts playing
window.sqVideoCallback = function(player, event) {
progress.style.display = "none";
Squeak.fileGet = fileGet;
Squeak.filePut = filePut;
if (player === PloppVideo && event === "close") {
delete window.sqVideoCallback;
PloppVideo.onclick = null;
// set up file download when writing to user/Plopp/
Squeak.filePut = function(path, data, ...args) {
if (path.startsWith("/Plopp/user/Plopp/") && data.byteLength > 0) {
console.log("downloading", path);
const file = path.replace(/.*\//, "");
const blob = new Blob([data], {type: file.endsWith(".jpg") ? "image/jpeg" : "application/octet-stream"});
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = file;
a.click();
URL.revokeObjectURL(url);
}
return filePut.call(Squeak, path, data, ...args);
};
}
};
}
function setupAudioVideo() {
// we will reuse the same Video object for all sounds
// so we can play without another user interaction
// (particularily on iOS)
window.PloppVideo = document.createElement("video");
PloppVideo.src = "index.mp3"; // yes, it's an mp3 in a video tag
PloppVideo.play();
// also play a silent audio to allow audio on iOS
window.PloppAudio = new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA");
// for some reason, timing is more accurate on iOS
// if we play through an audio context
const audioCtx = Squeak.startAudioOut();
const audioNode = audioCtx.createMediaElementSource(PloppAudio);
audioNode.connect(audioCtx.destination);
PloppAudio.play();
// generate an ESC key even when clicking the video
// so we can skip the intro video
PloppVideo.onclick = e => {
const { display } = SqueakJS.vm.primHandler;
display.eventQueue.push([
Squeak.EventTypeKeyboard,
e.timestamp,
27, // MacRoman
Squeak.EventKeyChar,
display.buttons >> 3,
27, // Unicode
]);
display.signalInputEvent();
};
}
function unixRuntime() {
// pretend to be unix
Squeak.platformName = "unix";
// we need a temp directory for printing
Squeak.dirCreate("/tmp");
return {
getModuleName() { return "libc.so (plopp)"; },
setInterpreter(proxy) { this.vm = proxy.vm; return true; },
getenv(v) {
if (v === "HOME") return "/Plopp/user";
console.warn("UNIMPLEMENTED getenv: " + v);
debugger
},
system(command) {
const argv = command.split(" ").map(a => a.replace(/^'(.*)'$/, "$1"));
if (argv[0] === "/SqueakJS/openbrowser.sh") {
const url = argv[1].replace(/^file:\/\/\/SqueakJS\/Plopp\//, "Contents/Resources/");
window.open(url);
return 0;
}
if (argv[0] === "/SqueakJS/print.sh") {
let file = argv[1]; // e.g. /tmp/plopp.jpg
let unfreeze = this.vm.freeze();
let url;
const proceed = () => {
if (file) { Squeak.fileDelete(file); file = null; }
if (url) { URL.revokeObjectURL(url); url = null; }
if (unfreeze) { unfreeze(); unfreeze = null; }
};
Squeak.fileGet(file,
data => {
const blob = new Blob([data], {type: "image/jpeg"});
url = URL.createObjectURL(blob);
const img = document.getElementById("printedimage");
img.src = url;
img.onload = () => {
window.print();
img.src = "";
proceed();
};
img.onerror = () => {
console.warn("print: failed to load " + file);
proceed();
};
}, err => {
console.warn("print: failed to get " + file);
file = null;
proceed();
});
return 0;
}
if (argv[0] === '/SqueakJS/setdesktop.sh') {
const file = argv[1]; // e.g. /Plopp/user/Plopp/plopp-wallpaper106128440.jpg
console.warn("UNIMPLEMENTED setdesktop: " + file);
return 0;
}
console.warn("UNIMPLEMENTED system command: " + command);
debugger
return 1;
},
};
}
</script>
</body>
</html>