@@ -17,27 +17,23 @@ import androidx.compose.ui.text.font.FontWeight
1717import androidx.compose.ui.unit.dp
1818import kotlinx.coroutines.CoroutineScope
1919import kotlinx.coroutines.Dispatchers
20+ import kotlinx.coroutines.GlobalScope
2021import kotlinx.coroutines.launch
2122import kotlinx.serialization.json.*
22- import processing.app.Base
23- import processing.app.Formatter
24- import processing.app.Messages
25- import processing.app.Mode
26- import processing.app.SketchException
23+ import processing.app.*
2724import processing.app.syntax.JEditTextArea
2825import processing.app.syntax.PdeTextArea
2926import processing.app.syntax.PdeTextAreaDefaults
30- import processing.app.ui.Editor
31- import processing.app.ui.EditorFooter
32- import processing.app.ui.EditorState
33- import processing.app.ui.EditorToolbar
27+ import processing.app.ui.*
3428import processing.app.ui.theme.ProcessingTheme
29+ import java.awt.event.ActionEvent
30+ import java.awt.event.ActionListener
3531import java.io.BufferedReader
3632import java.io.File
37- import java.io.IOException
3833import java.io.InputStreamReader
3934import java.net.URL
4035import javax.swing.JMenu
36+ import javax.swing.JMenuItem
4137
4238
4339class p5jsEditor (base : Base , path : String? , state : EditorState ? , mode : Mode ? ): Editor(base, path, state, mode) {
@@ -85,10 +81,8 @@ class p5jsEditor(base: Base, path: String?, state: EditorState?, mode: Mode?): E
8581
8682 // TODO: refactor into functions
8783 // Check whether `pnpm` is already installed; horrible code—my apologies!
88- // TODO: Make more robust, cross-platform, etc. Only job for now is to get a PDEX file out that works on MacOS
8984 statusNotice(" Looking for pnpm…" )
9085 try {
91- // TODO: Only an interactive shell allows me access to pnpm
9286 runCommand(" pnpm -v" )
9387 }
9488 catch (e: Exception ) {
@@ -127,9 +121,45 @@ class p5jsEditor(base: Base, path: String?, state: EditorState?, mode: Mode?): E
127121 }
128122
129123 override fun buildFileMenu (): JMenu {
130- return super .buildFileMenu(arrayOf())
124+ val exportApp: JMenuItem = Toolkit .newJMenuItemShift(Language .text(" menu.file.export_application" ), ' E' .code)
125+ exportApp.addActionListener(ActionListener { e: ActionEvent ? ->
126+ if (sketch.isUntitled || sketch.isReadOnly) {
127+ Messages .showMessage(" Save First" , " Please first save the sketch." );
128+ } else {
129+ // TODO: I’m sure this is not the best way to ensure that this runs async, so the ActionListener can return
130+ // but works for now
131+ scope.launch {
132+ handleExport()
133+ }
134+ }
135+ })
136+ return super .buildFileMenu(arrayOf(exportApp))
137+ }
138+
139+ private fun handleExport () {
140+ statusNotice(Language .text(" export.notice.exporting" ))
141+
142+ val electronBuilderBin = File (sketch.folder, " node_modules/.bin/electron-builder" )
143+ if (! electronBuilderBin.exists()) {
144+ runCommand(" pnpm install --dangerously-allow-all-builds --force" )
145+ }
146+
147+ runCommand(" pnpm app:pack" , onFinished = {
148+ Platform .openFolder(sketch.folder)
149+ statusNotice(Language .text(" export.notice.exporting.done" ))
150+ })
131151 }
132152
153+ // override fun handleSaveAs(): Boolean {
154+ // val saved = super.handleSaveAs()
155+ // statusNotice("Rebuilding Node dependencies…")
156+ // TODO: Saving is async and might not be finished once the function returns
157+ // runCommand("pnpm install --force", onFinished = {
158+ // statusNotice("Rebuilding Node dependencies… Done.")
159+ // })
160+ // return saved
161+ // }
162+
133163 override fun buildSketchMenu (): JMenu {
134164 return super .buildSketchMenu(arrayOf())
135165 }
0 commit comments