mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
remove double thread crap (make mac happy), fix full screen for mrj, auto-updater code
This commit is contained in:
+75
-3
@@ -20,7 +20,9 @@ implements ActionListener
|
||||
//app.setProgramFile(args[0]);
|
||||
//}
|
||||
|
||||
app.frame.show();
|
||||
// this is getting moved back inside the constructor
|
||||
// because it was for pockyvision, which is going away
|
||||
//app.frame.show();
|
||||
}
|
||||
|
||||
public PdeApplication() {
|
||||
@@ -58,8 +60,76 @@ implements ActionListener
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.add("Center", this);
|
||||
init();
|
||||
Insets insets = frame.getInsets();
|
||||
|
||||
/*
|
||||
// check for updates from the server, if enabled
|
||||
if (getBoolean("update.enabled", false)) {
|
||||
// open the update file to get the latest version
|
||||
long lastUpdate = 0;
|
||||
try {
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream("lib/version"));
|
||||
lastUpdate = dis.readLong();
|
||||
} catch (IOException e) { }
|
||||
|
||||
String baseUrl = get("update.url");
|
||||
try {
|
||||
URL url = new URL(baseUrl + "version");
|
||||
URLConnection conn = url.openConnection();
|
||||
//conn.connect();
|
||||
|
||||
//System.out.println("date of last update" + conn.getDate());
|
||||
long newDate = conn.getDate();
|
||||
if (newDate > lastUpdate) {
|
||||
System.out.println("new update available");
|
||||
|
||||
DataOutputStream vos =
|
||||
new DataOutputStream(new FileOutputStream("lib/version.update"));
|
||||
vos.writeLong(newDate);
|
||||
vos.flush();
|
||||
vos.close();
|
||||
|
||||
url = new URL(baseUrl + "pde.jar");
|
||||
conn = url.openConnection();
|
||||
|
||||
// move the old pde.jar file out of the way
|
||||
//File pdeJar = new File("lib/pde.jar");
|
||||
//pdeJar.renameTo("lib/pde.old.jar");
|
||||
|
||||
// download the new pde.jar file
|
||||
FileOutputStream os = new FileOutputStream("lib/pde.jar.update");
|
||||
//Object object = conn.getContent();
|
||||
//System.out.println(object);
|
||||
InputStream is = conn.getInputStream();
|
||||
copyStream(is, os);
|
||||
os.close();
|
||||
|
||||
// if everything copied ok, rename new/old files
|
||||
// this probably needs to be way more bulletproof
|
||||
File file = new File("lib/version");
|
||||
if (file.exists()) file.renameTo(new File("lib/version.old"));
|
||||
file = new File("lib/version.update");
|
||||
file.renameTo(new File("lib/version"));
|
||||
|
||||
file = new File("lib/pde.jar");
|
||||
file.renameTo(new File("lib/pde.jar.old"));
|
||||
file = new File("lib/pde.jar.update");
|
||||
file.renameTo(new File("lib/pde.jar"));
|
||||
|
||||
// restart or relaunch
|
||||
System.out.println("done copying new version, restart");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
|
||||
//} catch (MalformedURLException e2) {
|
||||
//e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Insets insets = frame.getInsets();
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
Dimension screen = tk.getScreenSize();
|
||||
int frameX = getInteger("window.x", (screen.width - width) / 2);
|
||||
@@ -76,9 +146,11 @@ implements ActionListener
|
||||
((PdeEditor)environment).frame = frame;
|
||||
|
||||
frame.pack();
|
||||
//frame.show();
|
||||
frame.show(); // added back in for pde
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef RECORDER
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String command = event.getActionCommand();
|
||||
|
||||
+22
-4
@@ -508,10 +508,28 @@ public class PdeEditor extends Panel implements PdeEnvironment {
|
||||
|
||||
|
||||
public void enableFullScreen() {
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
fullScreenWindow = new Window(new Frame());
|
||||
fullScreenWindow.setBounds(0, 0, screen.width, screen.height);
|
||||
fullScreenWindow.setBackground(new Color(102, 102, 102));
|
||||
if (fullScreenWindow == null) {
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
if (PdeApplet.isMacintosh()) {
|
||||
fullScreenWindow = new Frame();
|
||||
|
||||
// mrj is still (with version 2.2.x) a piece of shit,
|
||||
// and doesn't return valid insets for frames
|
||||
//fullScreenWindow.pack(); // make a peer so insets are valid
|
||||
//Insets insets = fullScreenWindow.getInsets();
|
||||
// the extra +20 is because the resize boxes intrude
|
||||
Insets insets = new Insets(21, 5, 5 + 20, 5);
|
||||
//System.out.println(insets);
|
||||
|
||||
fullScreenWindow.setBounds(-insets.left, -insets.top,
|
||||
screen.width + insets.left + insets.right,
|
||||
screen.height + insets.top + insets.bottom);
|
||||
} else {
|
||||
fullScreenWindow = new Window(new Frame());
|
||||
fullScreenWindow.setBounds(0, 0, screen.width, screen.height);
|
||||
}
|
||||
fullScreenWindow.setBackground(new Color(102, 102, 102));
|
||||
}
|
||||
fullScreenWindow.show();
|
||||
|
||||
// not sure what to do with applet..
|
||||
|
||||
@@ -34,6 +34,8 @@ public class PdeRunner implements Runnable {
|
||||
|
||||
|
||||
public void start() {
|
||||
run();
|
||||
/*
|
||||
if (thread != null) {
|
||||
try {
|
||||
thread.stop();
|
||||
@@ -42,6 +44,7 @@ public class PdeRunner implements Runnable {
|
||||
}
|
||||
thread = new Thread(this, "PdeRunner");
|
||||
thread.start();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -138,10 +141,12 @@ public class PdeRunner implements Runnable {
|
||||
public void stop() {
|
||||
if (engine != null) {
|
||||
engine.stop();
|
||||
/*
|
||||
if (forceStop) {
|
||||
thread.stop();
|
||||
thread = null;
|
||||
}
|
||||
*/
|
||||
engine = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class PdeUpdater {
|
||||
PdeUpdater() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream("lib/pde.properties"));
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error reading pde.properties");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// 'enabled' no longer valid because
|
||||
// this is a separate updater application
|
||||
boolean updateEnabled = true;
|
||||
//(new Boolean(properties.getProperty("update.enabled",
|
||||
// "false"))).booleanValue();
|
||||
|
||||
// check for updates from the server, if enabled
|
||||
//if (getBoolean("update.enabled", false)) {
|
||||
if (updateEnabled) {
|
||||
// open the update file to get the latest version
|
||||
long lastUpdate = 0;
|
||||
try {
|
||||
DataInputStream dis =
|
||||
new DataInputStream(new FileInputStream("lib/version"));
|
||||
lastUpdate = dis.readLong();
|
||||
//System.out.println("pde.jar timestamp is " + lastUpdate);
|
||||
} catch (IOException e) { }
|
||||
|
||||
//String baseUrl = get("update.url");
|
||||
String baseUrl = properties.getProperty("update.url");
|
||||
|
||||
try {
|
||||
URL url = new URL(baseUrl + "version");
|
||||
URLConnection conn = url.openConnection();
|
||||
//conn.connect();
|
||||
|
||||
//System.out.println("date of last update" + conn.getDate());
|
||||
long newDate = conn.getLastModified();
|
||||
//System.out.println("server timestamp is " + newDate);
|
||||
//System.out.println((newDate - lastUpdate) + "ms newer");
|
||||
if (newDate > lastUpdate) {
|
||||
System.out.println("new update available");
|
||||
|
||||
DataOutputStream vos =
|
||||
new DataOutputStream(new FileOutputStream("lib/version"));
|
||||
//new DataOutputStream(new FileOutputStream("lib/version.update"));
|
||||
vos.writeLong(newDate);
|
||||
vos.flush();
|
||||
vos.close();
|
||||
|
||||
url = new URL(baseUrl + "pde.jar");
|
||||
conn = url.openConnection();
|
||||
|
||||
// move the old pde.jar file out of the way
|
||||
//File pdeJar = new File("lib/pde.jar");
|
||||
//pdeJar.renameTo("lib/pde.old.jar");
|
||||
|
||||
// download the new pde.jar file
|
||||
//FileOutputStream os = new FileOutputStream("lib/pde.jar.update");
|
||||
FileOutputStream os = new FileOutputStream("lib/pde.jar");
|
||||
//Object object = conn.getContent();
|
||||
//System.out.println(object);
|
||||
InputStream is = conn.getInputStream();
|
||||
copyStream(is, os);
|
||||
os.close();
|
||||
|
||||
// if everything copied ok, rename new/old files
|
||||
// this probably needs to be way more bulletproof
|
||||
/*
|
||||
File file = new File("lib/version");
|
||||
if (file.exists())
|
||||
System.out.println(file.renameTo(new File("lib/version.old")));
|
||||
file = new File("lib/version.update");
|
||||
System.out.println(file.renameTo(new File("lib/version")));
|
||||
|
||||
file = new File("lib/pde.jar");
|
||||
file.delete();
|
||||
//System.out.println(file.renameTo(new File("lib/pde.jar.old")));
|
||||
file = new File("lib/pde.jar.update");
|
||||
System.out.println(file.renameTo(new File("lib/pde.jar")));
|
||||
*/
|
||||
|
||||
// restart or relaunch
|
||||
//System.out.println("done copying new version, restart");
|
||||
//System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
try {
|
||||
Class c = Class.forName("PdeApplication");
|
||||
Object o = c.newInstance();
|
||||
//PdeApplication.main(null);
|
||||
} catch (Exception e) {
|
||||
System.err.println("update failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
|
||||
//} catch (MalformedURLException e2) {
|
||||
//e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void copyStream(InputStream input, OutputStream output
|
||||
/*int padding, long length*/)
|
||||
throws IOException {
|
||||
byte[] buffer = new byte[4096];
|
||||
int count;
|
||||
int amount;
|
||||
|
||||
int length = Integer.MAX_VALUE;
|
||||
// if length is not actually known, the function will still break
|
||||
// in the correct spot, so just set to some enormous value
|
||||
//if (length == -1) {
|
||||
//length = Integer.MAX_VALUE;
|
||||
//}
|
||||
//if (padding != 0) {
|
||||
//input.skip((int) padding);
|
||||
//}
|
||||
|
||||
while (true) {
|
||||
amount = (length < 4096) ? (int) length : 4096;
|
||||
//System.err.print(amount + " ");
|
||||
count = input.read(buffer, 0, amount);
|
||||
//System.out.println("got " + count);
|
||||
if (count == -1)
|
||||
break;
|
||||
|
||||
output.write(buffer, 0, count);
|
||||
length -= count; // used to be amount... bug?
|
||||
if (length == 0)
|
||||
break;
|
||||
}
|
||||
output.flush();
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
new PdeUpdater();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user