Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Uniq : single instance applications made easy
Uniq : single instance applications made easy [message #31118] Sun, 06 February 2011 00:27 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1294
Registered: September 2007
Senior Contributor
I started Uniq class, by now working just for Linux,windows part in development. It allows to have a single application instance running and other instances passing their command line to it.
Example code :

UniqTest.lay :
LAYOUT(UniqTestLayout, 404, 240)
	ITEM(LineEdit, edit, SetEditable(false).WantFocus(false).LeftPosZ(8, 388).TopPosZ(8, 220))
END_LAYOUT


UniqTest.h :
#ifndef _UniqTest_UniqTest_h
#define _UniqTest_UniqTest_h

#include <CtrlLib/CtrlLib.h>

#include <Uniq/Uniq.h>

using namespace Upp;

#define LAYOUTFILE <UniqTest/UniqTest.lay>
#include <CtrlCore/lay.h>

class UniqTest : public WithUniqTestLayout<TopWindow>
{
	private:
	public:
		typedef UniqTest CLASSNAME;
		UniqTest();

		// handles news app instances
		void handleInstance(Vector<String> const &v);
		
};


UniqTest.cpp :
#include "UniqTest.h"

UniqTest::UniqTest()
{
	CtrlLayout(*this, "Window title");
}

// handles news app instances
void UniqTest::handleInstance(Vector<String> const &v)
{
	String s = edit.Get() + "NEW INSTANCE LAUNCHED\n  Command line : '";
	for(int i = 0; i < v.GetCount(); i++)
		s += v[i] + ",";
	if(s[s.GetCount() - 1] == ',')
		s = s.Left(s.GetCount()-1);
	s += "\n";
	
	edit <<= s;
	ProcessEvents();
}

GUI_APP_MAIN
{
	// create Uniq object
	Uniq uniq;
	
	// if not inside first instance, send commandline
	// to first instance and leave
	if(!uniq)
		return;
	
	UniqTest uniqTest;

	// setup callback handling other app's instances
	uniq.WhenInstance = callback(&uniqTest, &UniqTest::handleInstance);
		
	uniqTest.Run();
}



This code allows first app instance to start. If you start other instances, their Command Line is routed to it with a posted callback, allowing opened instance, for example, to open a file.
In this small example, it just echoes command line of newly started apps.

Ciao

Max
Re: Uniq : single instance applications made easy [message #31132 is a reply to message #31118] Mon, 07 February 2011 23:04 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1294
Registered: September 2007
Senior Contributor
Now working both on windows and Linux.

On the way, I've seen how M$ people can complicate simple stuffs...

Ciao

Max
Re: Uniq : single instance applications made easy [message #58731 is a reply to message #31118] Tue, 09 August 2022 17:27 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 8
Registered: August 2022
Promising Member
I know this is an old post. When I try to include Uniq/Uniq.h it fails and I have searched the source files and it does not seem to exist. Is this old code that has been removed or it it in some other repository?
Re: Uniq : single instance applications made easy [message #58744 is a reply to message #58731] Fri, 12 August 2022 15:12 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1294
Registered: September 2007
Senior Contributor
Hi Mirek,

I've got Uniq.t file... here is its content:

#ifdef _MSC_VER
#pragma setlocale("C")
#endif
// Posix.cpp

T_("Error creating interprocess pipe")
caES("")
deDE("")
esES("Error al crear el pipe entre procesos")
itIT("")

T_("Error locking lock file")
caES("")
deDE("")
esES("Error al bloquear el fichero de bloqueo")
itIT("")


It's not from me, as it's in spanish, I guess it was added by somebody else...
Re: Uniq : single instance applications made easy [message #58745 is a reply to message #58731] Sat, 13 August 2022 10:12 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 187
Registered: June 2011
Experienced Member
devilsclaw wrote on Tue, 09 August 2022 17:27
I know this is an old post. When I try to include Uniq/Uniq.h it fails and I have searched the source files and it does not seem to exist. Is this old code that has been removed or it it in some other repository?


Uniq is in UppHub, it's part of Libraries4U.

Read about UppHub here:
https://www.ultimatepp.org/app$ide$UppHub_en-us.html
Previous Topic: Scatter: DataRange for explicit functions
Next Topic: SixelRaster package for U++
Goto Forum:
  


Current Time: Wed Dec 07 02:04:49 CET 2022

Total time taken to generate the page: 0.01431 seconds