From 0333b484ef855898595a51db9dc22de5f8d4197c Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 17 Apr 2005 16:38:01 +0000 Subject: [PATCH] working on the application, and implemented update check --- app/Base.java | 15 ++-- app/Editor.java | 4 +- app/Preferences.java | 29 ++++--- app/UpdateCheck.java | 119 ++++++++++++++++++++++++++ build/shared/lib/preferences.txt | 6 ++ build/windows/launcher/processing.exe | Bin 123829 -> 123829 bytes todo.txt | 9 +- 7 files changed, 158 insertions(+), 24 deletions(-) create mode 100644 app/UpdateCheck.java diff --git a/app/Base.java b/app/Base.java index c16ce5a12..038fd895e 100644 --- a/app/Base.java +++ b/app/Base.java @@ -50,7 +50,8 @@ import processing.core.*; * files and images, etc) that comes from that. */ public class Base { - static final String VERSION = "0083 Alpha"; + static final int VERSION = 83; + static final String VERSION_NAME = "0083 Alpha"; /** * Path of filename opened on the command line, @@ -68,9 +69,9 @@ public class Base { if (PApplet.javaVersion < 1.4f) { //System.err.println("no way man"); Base.showError("Need to install Java 1.4", - "This version of Processing requires \n" + - "Java 1.4 or later to run properly.\n" + - "Please visit java.com to upgrade.", null); + "This version of Processing requires \n" + + "Java 1.4 or later to run properly.\n" + + "Please visit java.com to upgrade.", null); } @@ -118,7 +119,6 @@ public class Base { e.printStackTrace(); } - // build the editor object editor = new Editor(); @@ -130,6 +130,11 @@ public class Base { // show the window editor.show(); + + // check for updates + if (Preferences.getBoolean("update.check")) { + new UpdateCheck(editor); + } } diff --git a/app/Editor.java b/app/Editor.java index 82677a0b0..b43b2dac6 100644 --- a/app/Editor.java +++ b/app/Editor.java @@ -51,7 +51,7 @@ public class Editor extends JFrame MRJOpenDocumentHandler //, MRJOpenApplicationHandler { // yeah - static final String WINDOW_TITLE = "Processing" + " - " + Base.VERSION; + static final String WINDOW_TITLE = "Processing" + " - " + Base.VERSION_NAME; // p5 icon for the window Image icon; @@ -874,7 +874,7 @@ public class Editor extends JFrame g.setFont(new Font("SansSerif", Font.PLAIN, 11)); g.setColor(Color.white); - g.drawString(Base.VERSION, 50, 30); + g.drawString(Base.VERSION_NAME, 50, 30); } }; window.addMouseListener(new MouseAdapter() { diff --git a/app/Preferences.java b/app/Preferences.java index 0549a3ba9..7435a2daa 100644 --- a/app/Preferences.java +++ b/app/Preferences.java @@ -73,12 +73,11 @@ public class Preferences extends JComponent { // mac needs it to be 70, windows needs 66, linux needs 76 - static /*final*/ int BUTTON_WIDTH = 76; - static /*final*/ int BUTTON_HEIGHT = 24; + static int BUTTON_WIDTH = 76; + static int BUTTON_HEIGHT = 24; // value for the size bars, buttons, etc - //static final int INSET_SIZE = 5; static final int GRID_SIZE = 33; // gui variables @@ -98,6 +97,7 @@ public class Preferences extends JComponent { JCheckBox sketchCleanBox; //JCheckBox exportLibraryBox; JCheckBox externalEditorBox; + JCheckBox checkUpdatesBox; JTextField fontSizeField; @@ -123,7 +123,7 @@ public class Preferences extends JComponent { } catch (Exception e) { Base.showError(null, "Could not read default settings.\n" + - "You'll need to reinstall Processing.", e); + "You'll need to reinstall Processing.", e); } // check for platform-specific properties in the defaults @@ -307,6 +307,16 @@ public class Preferences extends JComponent { top += d.height + GUI_BETWEEN; + // [ ] Check for updates on startup + + checkUpdatesBox = new JCheckBox("Check for updates on startup"); + pain.add(checkUpdatesBox); + d = checkUpdatesBox.getPreferredSize(); + checkUpdatesBox.setBounds(left, top, d.width, d.height); + right = Math.max(right, left + d.width); + top += d.height + GUI_BETWEEN; + + // More preferences are in the ... /* @@ -433,9 +443,6 @@ public class Preferences extends JComponent { * Close the window after an OK or Cancel. */ public void disposeFrame() { - //frame.hide(); - //editor.applyPreferences(); - //editor.show(); frame.dispose(); } @@ -445,14 +452,12 @@ public class Preferences extends JComponent { * then send a message to the editor saying that it's time to do the same. */ public void applyFrame() { - //editor.setExternalEditor(getBoolean("editor.external")); // put each of the settings into the table - setBoolean("sketchbook.prompt", sketchPromptBox.isSelected()); setBoolean("sketchbook.auto_clean", sketchCleanBox.isSelected()); set("sketchbook.path", sketchbookLocationField.getText()); - //setBoolean("export.library", exportLibraryBox.isSelected()); setBoolean("editor.external", externalEditorBox.isSelected()); + setBoolean("update.check", checkUpdatesBox.isSelected()); String newSizeText = fontSizeField.getText(); try { @@ -469,16 +474,14 @@ public class Preferences extends JComponent { public void showFrame(Editor editor) { - // hide the editor window so it can't be messed with this.editor = editor; - //editor.hide(); // set all settings entry boxes to their actual status sketchPromptBox.setSelected(getBoolean("sketchbook.prompt")); sketchCleanBox.setSelected(getBoolean("sketchbook.auto_clean")); sketchbookLocationField.setText(get("sketchbook.path")); - //exportLibraryBox.setSelected(getBoolean("export.library")); externalEditorBox.setSelected(getBoolean("editor.external")); + checkUpdatesBox.setSelected(getBoolean("update.check")); frame.show(); } diff --git a/app/UpdateCheck.java b/app/UpdateCheck.java new file mode 100644 index 000000000..59e702016 --- /dev/null +++ b/app/UpdateCheck.java @@ -0,0 +1,119 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2005 Ben Fry and Casey Reas + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package processing.app; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.lang.reflect.*; +import java.net.*; +import java.util.*; +import java.util.zip.*; + +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.text.*; +import javax.swing.undo.*; + +import com.apple.mrj.*; +import com.ice.jni.registry.*; + +import processing.core.*; + + +/** + * Threaded class to check for updates. + *

+ * This generates a random id number for this user, + * and hits the server to check for updates. + * The id number is used so that we can keep track of + * how many people are using Processing, which helps us + * when writing grant proposals and that kind of thing. + */ +public class UpdateCheck implements Runnable { + Editor editor; + String downloadURL = "http://processing.org/download/latest.txt"; + + + public UpdateCheck(Editor editor) { + this.editor = editor; + Thread thread = new Thread(this); + thread.start(); + } + + + public void run() { + //System.out.println("checking for updates..."); + + // generate a random id in case none exists yet + Random r = new Random(); + long id = r.nextLong(); + + String idString = Preferences.get("update.id"); + if (idString != null) { + id = Long.parseLong(idString); + } else { + Preferences.set("update.id", String.valueOf(id)); + } + + try { + //int id = PApplet.parseInt(idString); + //int latest = PApplet.toInt(PApplet.loadStrings()); + int latest = readInt(downloadURL + "?" + id); + + String prompt = + "A new version of Processing is available,\n" + + "would you like to visit the Processing download page?"; + + if (latest > Base.VERSION) { + Object[] options = { "Yes", "No" }; + int result = JOptionPane.showOptionDialog(editor, + prompt, + "Update", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[0]); + + if (result == JOptionPane.YES_OPTION) { + Base.openURL("http://processing.org/download/"); + + //} else if (result == JOptionPane.NO_OPTION) { + } + } + } catch (Exception e) { + e.printStackTrace(); + System.err.println("Error while trying to check for an update."); + } + } + + + protected int readInt(String filename) throws Exception { + URL url = new URL(filename); + InputStream stream = url.openStream(); + InputStreamReader isr = new InputStreamReader(stream); + BufferedReader reader = new BufferedReader(isr); + return Integer.parseInt(reader.readLine()); + } +} diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt index 4586d0c59..06a3617d0 100755 --- a/build/shared/lib/preferences.txt +++ b/build/shared/lib/preferences.txt @@ -43,6 +43,12 @@ settings.path.fallback=data # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# by default, check the processing server for any updates +# (please avoid disabling, this also helps us know basic numbers +# on how many people are using Processing) +update.check = true + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # default size for the main window default.window.width = 500 diff --git a/build/windows/launcher/processing.exe b/build/windows/launcher/processing.exe index ce98531b2e5d195ee2b50db9cc3d18204e7655e7..3d63723d461c3f8098eda6086a67a47ea265b82e 100755 GIT binary patch delta 94 zcmdmboPFzY_6Z%#;r&SyyM38H>TJB_#liStvMOf)4ICIcLsU3+EHHFn yc)i2$e`k#f&%UpdA8^V6Rs83)0+Lo-vW#ChM{rHznfzAFxLHzq3Y#XWx&>4>;w3D*kg?0ZA(^S;ilmBe*8KOo< CbtZWL diff --git a/todo.txt b/todo.txt index 295e31b4d..f70d9b525 100644 --- a/todo.txt +++ b/todo.txt @@ -56,6 +56,11 @@ X then call them inside post() saturday evening and sunday morning X scrubbing all the code to include proper license and copyright info +sunday afternoon +X update checker (can be turned off in prefs) +X send unique id, and information about person's java vm/platform +o using timezone would be an interesting method for tracking location + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -78,10 +83,6 @@ _ code is larger than we'd like, has increased in size _ working to remove and optimize, also make possible to remove un-needed _ setup bugzilla, move legit bugs there, non-bugs to readme -_ update checker (can be turned off in prefs) -_ send unique id, and information about person's java vm/platform -_ using timezone would be an interesting method for tracking location - // SAVE AS BUGS