Skip to content

Commit db69773

Browse files
committed
Refactor beta welcome window handling
Replaces custom JFrame setup in WelcomeToBeta with PDESwingWindow and PDEComposeWindow, centralizing window logic and close handling. Adds onClose callback to PDESwingWindow for improved lifecycle management. Also ensures beta welcome preference is reset on forced update check.
1 parent 58c746b commit db69773

File tree

3 files changed

+18
-47
lines changed

3 files changed

+18
-47
lines changed

app/src/processing/app/ui/Editor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ public void buildDevelopMenu(){
10571057
var updateTrigger = new JMenuItem(Language.text("menu.develop.check_for_updates"));
10581058
updateTrigger.addActionListener(e -> {
10591059
Preferences.unset("update.last");
1060+
Preferences.setInteger("update.beta_welcome", 0);
10601061
new UpdateCheck(base);
10611062
});
10621063
developMenu.add(updateTrigger);

app/src/processing/app/ui/WelcomeToBeta.kt

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import processing.app.Base.getVersionName
4141
import processing.app.ui.theme.LocalLocale
4242
import processing.app.ui.theme.LocalTheme
4343
import processing.app.ui.theme.Locale
44+
import processing.app.ui.theme.PDEComposeWindow
45+
import processing.app.ui.theme.PDESwingWindow
4446
import processing.app.ui.theme.ProcessingTheme
4547
import java.awt.Cursor
4648
import java.awt.Dimension
@@ -54,46 +56,20 @@ import javax.swing.SwingUtilities
5456

5557
class WelcomeToBeta {
5658
companion object{
57-
val windowSize = Dimension(400, 200)
58-
val windowTitle = Locale()["beta.window.title"]
59-
6059
@JvmStatic
6160
fun showWelcomeToBeta() {
62-
val mac = SystemInfo.isMacFullWindowContentSupported
6361
SwingUtilities.invokeLater {
64-
JFrame(windowTitle).apply {
65-
val close = {
66-
Preferences.set("update.beta_welcome", getRevision().toString())
67-
dispose()
68-
}
69-
rootPane.putClientProperty("apple.awt.transparentTitleBar", mac)
70-
rootPane.putClientProperty("apple.awt.fullWindowContent", mac)
71-
defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE
72-
contentPane.add(ComposePanel().apply {
73-
size = windowSize
74-
setContent {
75-
ProcessingTheme {
76-
Box(modifier = Modifier.padding(top = if (mac) 22.dp else 0.dp)) {
77-
welcomeToBeta(close)
78-
}
79-
}
80-
}
81-
})
82-
pack()
83-
background = java.awt.Color.white
84-
setLocationRelativeTo(null)
85-
addKeyListener(object : KeyAdapter() {
86-
override fun keyPressed(e: KeyEvent) {
87-
if (e.keyCode == KeyEvent.VK_ESCAPE) close()
88-
}
89-
})
90-
isResizable = false
91-
isVisible = true
92-
requestFocus()
62+
val close = {
63+
Preferences.set("update.beta_welcome", getRevision().toString())
64+
}
65+
66+
PDESwingWindow("beta.window.title", onClose = close) {
67+
welcomeToBeta(close)
9368
}
9469
}
9570
}
9671

72+
val windowSize = Dimension(400, 200)
9773
@Composable
9874
fun welcomeToBeta(close: () -> Unit = {}) {
9975
Row(
@@ -194,18 +170,9 @@ class WelcomeToBeta {
194170
@JvmStatic
195171
fun main(args: Array<String>) {
196172
application {
197-
val windowState = rememberWindowState(
198-
size = DpSize.Unspecified,
199-
position = WindowPosition(Alignment.Center)
200-
)
201-
202-
Window(onCloseRequest = ::exitApplication, state = windowState, title = windowTitle) {
203-
ProcessingTheme {
204-
Surface(color = colors.background) {
205-
welcomeToBeta {
206-
exitApplication()
207-
}
208-
}
173+
PDEComposeWindow(titleKey = "beta.window.title", onClose = ::exitApplication){
174+
welcomeToBeta {
175+
exitApplication()
209176
}
210177
}
211178
}

app/src/processing/app/ui/theme/Window.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ val LocalWindow = compositionLocalOf<JFrame> { error("No Window Set") }
4040
* @param fullWindowContent If true, the content will extend into the title bar area on macOS.
4141
* @param content The composable content to be displayed in the window.
4242
*/
43-
class PDESwingWindow(titleKey: String = "", fullWindowContent: Boolean = false, content: @Composable BoxScope.() -> Unit): JFrame(){
43+
class PDESwingWindow(titleKey: String = "", fullWindowContent: Boolean = false, onClose: () -> Unit = {}, content: @Composable BoxScope.() -> Unit): JFrame(){
4444
init{
4545
val window = this
4646
defaultCloseOperation = DISPOSE_ON_CLOSE
@@ -54,7 +54,10 @@ class PDESwingWindow(titleKey: String = "", fullWindowContent: Boolean = false,
5454
setLocationRelativeTo(null)
5555
addKeyListener(object : KeyAdapter() {
5656
override fun keyPressed(e: KeyEvent) {
57-
if (e.keyCode == KeyEvent.VK_ESCAPE) window.dispose()
57+
if (e.keyCode != KeyEvent.VK_ESCAPE) return
58+
59+
window.dispose()
60+
onClose()
5861
}
5962
})
6063
isResizable = false

0 commit comments

Comments
 (0)