New instance hands off to existing one

master
skylarmt 9 years ago
parent b57c1927e2
commit 882a3c469a

File diff suppressed because it is too large Load Diff

@ -118,6 +118,10 @@ public class Main extends javax.swing.JFrame {
* Application icon, for setting frame icons.
*/
public static ArrayList<Image> symatlogo = new ArrayList<>();
public static SingleInstanceServer sisrv;
public static Main maingui;
/**
* Creates the main app window and does some quick things that aren't
@ -125,6 +129,7 @@ public class Main extends javax.swing.JFrame {
*/
public Main() {
initComponents();
maingui = this;
// Set icon
setIconImages(symatlogo);
@ -1006,6 +1011,15 @@ public class Main extends javax.swing.JFrame {
break;
}
}
SingleInstanceClient sicli = new SingleInstanceClient(argfile);
try {
new SingleInstanceServer().start();
} catch (IOException ex) {
Debug.printerr("Cannot start instance listener:\n\n");
Debug.stacktrace(ex);
}
Platform.setImplicitExit(false);

@ -0,0 +1,82 @@
/*
* CODE LICENSE =====================
* Copyright (c) 2015, Apocalypse Laboratories
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. You adhere to the Media License detailed below. If you do not, this license
* is automatically revoked and you must purge all copies of the software you
* possess, in source or binary form.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* MEDIA LICENSE ====================
* All images and other graphical files (the "graphics") included with this
* software are copyright (c) 2015 Apocalypse Laboratories. You may not distribute
* the graphics or any program, source code repository, or other digital storage
* media containing them without written permission from Apocalypse Laboratories.
* This ban on distribution only applies to publicly available systems.
* A password-protected network file share, USB drive, or other storage scheme that
* cannot be easily accessed by the public is generally allowed. If in doubt,
* contact Apocalypse Laboratories. If Apocalypse Laboratories allows or denies
* you permission, that decision is considered final and binding.
*/
package net.apocalypselabs.symat;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
/**
* This class attempts to send startup data to an existing instance, and if it
* succeeds it kills this instance of SyMAT.
*
* @author Skylar
*/
public class SingleInstanceClient {
public SingleInstanceClient(String arg) {
String response = "";
String args = (arg.equals("") ? "" : "?arg=" + arg);
try {
URL url = new URL("http://127.0.0.1:26879" + args);
InputStream is = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
br.close();
is.close();
response = line;
} catch (Exception ex) {
}
if (response.equals("OK")) {
Debug.println("Handing off to original instance...");
System.exit(0);
}
}
}

@ -0,0 +1,81 @@
/*
* CODE LICENSE =====================
* Copyright (c) 2015, Apocalypse Laboratories
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. You adhere to the Media License detailed below. If you do not, this license
* is automatically revoked and you must purge all copies of the software you
* possess, in source or binary form.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* MEDIA LICENSE ====================
* All images and other graphical files (the "graphics") included with this
* software are copyright (c) 2015 Apocalypse Laboratories. You may not distribute
* the graphics or any program, source code repository, or other digital storage
* media containing them without written permission from Apocalypse Laboratories.
* This ban on distribution only applies to publicly available systems.
* A password-protected network file share, USB drive, or other storage scheme that
* cannot be easily accessed by the public is generally allowed. If in doubt,
* contact Apocalypse Laboratories. If Apocalypse Laboratories allows or denies
* you permission, that decision is considered final and binding.
*/
package net.apocalypselabs.symat;
import fi.iki.elonen.NanoHTTPD;
import java.util.Map;
/**
*
* @author Skylar
*/
public class SingleInstanceServer extends NanoHTTPD {
public SingleInstanceServer() {
super(26879);
}
@Override
public Response serve(IHTTPSession session) {
Debug.println("Another instance detected");
String msg = "OK";
Map<String, String> parms = session.getParms();
if (parms.get("arg") != null) {
CodeEditor ed = new CodeEditor();
Main.loadFrame(ed);
ed.openFileFromName(parms.get("arg"));
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Main.maingui.toFront();
Main.maingui.repaint();
}
});
}
return new NanoHTTPD.Response(msg);
}
}

@ -140,4 +140,4 @@
</SubComponents>
</Container>
</SubComponents>
</Form>
</Form>

@ -50,7 +50,6 @@ import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import static net.apocalypselabs.symat.Main.API_URL;
import static net.apocalypselabs.symat.Main.APP_CODE;
@ -67,7 +66,7 @@ public class SplashScreen extends javax.swing.JFrame {
*/
public SplashScreen() {
initComponents();
setBackground(new Color(0, 0, 0, 0));
setBackground(new Color(255, 255, 255, 0));
setIconImages(Main.symatlogo);
setLocationRelativeTo(null);
}
@ -103,7 +102,7 @@ public class SplashScreen extends javax.swing.JFrame {
jLayeredPane1.setBackground(new java.awt.Color(255, 255, 255));
dispLabel.setFont(Main.ubuntuRegular.deriveFont(22.0F));
dispLabel.setFont(net.apocalypselabs.symat.Main.ubuntuRegular.deriveFont(22.0F));
dispLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
dispLabel.setText("Loading...");
dispLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
@ -111,9 +110,9 @@ public class SplashScreen extends javax.swing.JFrame {
jLayeredPane1.add(dispLabel);
dispLabel.setBounds(250, 250, 350, 80);
jLabel1.setFont(Main.ubuntuRegular.deriveFont(20.0F));
jLabel1.setFont(net.apocalypselabs.symat.Main.ubuntuRegular.deriveFont(20.0F));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel1.setText("v. "+Main.VERSION_NAME);
jLabel1.setText("v. "+net.apocalypselabs.symat.Main.VERSION_NAME);
jLayeredPane1.add(jLabel1);
jLabel1.setBounds(520, 70, 80, 30);
jLayeredPane1.setLayer(jLabel1, javax.swing.JLayeredPane.POPUP_LAYER);
@ -122,14 +121,14 @@ public class SplashScreen extends javax.swing.JFrame {
jLayeredPane1.add(jLabel2);
jLabel2.setBounds(0, 0, 700, 470);
jLabel3.setFont(Main.ubuntuRegular.deriveFont(12.0F));
jLabel3.setFont(net.apocalypselabs.symat.Main.ubuntuRegular.deriveFont(12.0F));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("<html><div style=\"text-align: center;\">Apocalypse<br>Laboratories</div>");
jLayeredPane1.add(jLabel3);
jLabel3.setBounds(50, 420, 120, 40);
jLayeredPane1.setLayer(jLabel3, javax.swing.JLayeredPane.POPUP_LAYER);
jLabel4.setFont(Main.ubuntuRegular.deriveFont(12.0F));
jLabel4.setFont(net.apocalypselabs.symat.Main.ubuntuRegular.deriveFont(12.0F));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("symatapp.com");
jLayeredPane1.add(jLabel4);

Loading…
Cancel
Save