launching livecode files in Windows in one instance of LiveCode

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

launching livecode files in Windows in one instance of LiveCode

Post by golife » Wed Oct 02, 2024 6:13 pm

In Windows 11 double clicking a .livecode file (application extension:.livecode, .rev) opens that file in a new instance of LiveCode.exe which I want to prevent. I want to open the file in the IDE of the currently executing LiveCode instance as if opening from the IDE. Maybe I have overseen a solution to this, or I cannot find a solution despite searching. I can prevent LiveCode from starting another process using system tools, but that does not help since the LIveCode file shall still open which is not possible stopping a new process.
Any suggestions? Roland

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by Klaus » Wed Oct 02, 2024 6:32 pm

Hi Roland,

check "relaunch" in the dictionary, sounds like that is what you need. :-)

Best

Klaus

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: launching livecode files in Windows in one instance of LiveCode

Post by golife » Wed Oct 02, 2024 10:56 pm

Klaus, thank you for your reply. I had checked that. It does not work in the IDE, only for standalones.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by Klaus » Thu Oct 03, 2024 8:59 am

Hi Roland,

hm, if I remember correctly, this is the official way to do so.

Sorry, was in a hurry yesterday. Did you add a handler like this to your stack
that should be opened after the IDE had started:

Code: Select all

##Stackskript or script of first card:
on relaunch
  ### NADA
end relaunch
Best

Klaus

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: launching livecode files in Windows in one instance of LiveCode

Post by golife » Thu Oct 03, 2024 8:12 pm

Klaus:

Code: Select all

on relaunch
-- quit ---- :-)
end relaunch
is not recognized in the IDE. It does not fire.

I cannot think of any solution that is simply scriptable. When opening a file from anywhere except from inside a running instance, a new instance is started. In some cases, this may be desired. In most cases, I do not want it.

What I could do is check with a command line program if an instance of LiveCode.exe is running, and if YES, then intercepting every call to LiveCode.exe on the system level (redirecting to a message sending app using regedit) and using sockets in a library stack that would receive the path of the file to be opened as the message.

The running LiveCode.exe process would then be opening the file processing the message received. But it is no-standard, and it requires Admin rights to install -- at least I think so. I must check it. Possibly, an external C-program hooked into LiveCode could also do this directly inside of LiveCode.exe. I am not sure and not knowledgeable enough to work on this. And I also doubt that LiveCode builder could help here. But what do I really know? :P

I am still hoping that an easier solution exists to prevent a relaunch in the IDE and opens double-clicked files in the running process.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by FourthWorld » Thu Oct 03, 2024 8:50 pm

golife wrote:
Thu Oct 03, 2024 8:12 pm
I am still hoping that an easier solution exists to prevent a relaunch in the IDE and opens double-clicked files in the running process.
A unique application would need a unique file extension to distinguish its document type.

Once you do that, Klaus did not lead you astray: the relaunch message is indeed the way to prevent documents from launching a new instance, instead opening in the running instance.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by Klaus » Thu Oct 03, 2024 8:54 pm

I just made a test and it works as I told you!

1. I created a new stack "test1" with this "dummy" handler in the script of its first cd:

Code: Select all

on relaunch
  ##
end relaunch
2. I closed it and created another stack.
3. I double-clicked the stack "test1" and it was opended in the already running instance of Livecode.
Did you try exactly this?
relaunch.png

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: launching livecode files in Windows in one instance of LiveCode

Post by golife » Thu Oct 03, 2024 10:24 pm

Yes, I tried exactly this. Even before writing of course. You are on Windows?
That is interesting. Are there any settings that may be different?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by FourthWorld » Thu Oct 03, 2024 11:07 pm

What file extension are you using for your LiveCode stackfile documents?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: launching livecode files in Windows in one instance of LiveCode

Post by golife » Thu Oct 03, 2024 11:11 pm

Just to make sure that I am not mistake, I tested it with three different stacks.

The script is in the stack script. The stack is not dependent on any other stack or resources.

Code: Select all

on relaunch
   ##
end relaunch
Now, for example, saving a copy of the stack to the same folder the running stack is located, and double-clicking that file, opens the file in another window and launches LiveCode as a new instance. Having done this twice, there are now two menu bars, to tools-palettes, etc.

The handler for such an event is never triggered and does not receive such message even though it should (or not)?

The dictionary finally states:
"Note: This feature is only available in the standalone engine, as the IDE engine uses the relaunch facitily to suport loading of stack files into an existing instance of the IDE by double clicking on a file in the Windows shell." --
What does it mean? What is double clicking in a file in the Windows shell? I am running latest version of Windows 11 and the latest LiveCode 9.6.13. But whatever the configuration -- I also tested on other machines -- the result is the same.

The dictionary also says:
If there are no existing instances, the new instance will run.
The relaunch message is passed a variable number of arguments depending on the command-line the new instance is started up with. The processing is the same that is performed for the $n global variables before application startup. i.e. the command-line string is split into words, each word has any leading and trailing quotes stripped and '\' is replaced by '/'.
Maybe there is some hint in here? The $n global?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by Klaus » Fri Oct 04, 2024 1:15 pm

Hi Roland
golife wrote:
Thu Oct 03, 2024 10:24 pm
You are on Windows?
I started a VM machine (via Paralells on my Mac) with Win11 for testing.
golife wrote:
Thu Oct 03, 2024 10:24 pm
Are there any settings that may be different?
No, this is a fresh installation, did not set anything in Windows so far.

Best

Klaus

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by Klaus » Fri Oct 04, 2024 1:19 pm

golife wrote:
Thu Oct 03, 2024 11:11 pm
The dictionary finally states:
"Note: This feature is only available in the standalone engine, as the IDE engine uses the relaunch facitily to suport loading of stack files into an existing instance of the IDE by double clicking on a file in the Windows shell." --
What does it mean? What is double clicking in a file in the Windows shell?
this just means double-clicking a LC file on the desktop or any open folder.

I also means that the "dummy" handler is not even neccessary, the IDE takes care of this.
So if this is not the case for you, then there is something else going on on your machine!

Try to de-install and re-install LC, maybe that will help

golife
Posts: 115
Joined: Fri Apr 02, 2010 12:10 pm

Re: launching livecode files in Windows in one instance of LiveCode

Post by golife » Sat Oct 05, 2024 5:42 pm

Yes, as I said from the beginning, the relaunch handler only seems to work in a standalone, as the dictionary states. Yes, I am using Windows 11 latest version. Klaus made another observation, but I cannot reproduce. I am uskng .livecodei or .rev as the file extensions.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: launching livecode files in Windows in one instance of LiveCode

Post by FourthWorld » Sat Oct 05, 2024 6:43 pm

golife wrote:
Sat Oct 05, 2024 5:42 pm
I am uskng .livecodei or .rev as the file extensions.
Those file extensions are associated with the LiveCode application. That's the missing piece here, file associations.

There really should be a more complete Lesson on document handing, but this tutorial from Ken Ray will point you in the right direction:
http://sonsothunder.com/devres/livecode ... ile004.htm

In short, OSes need some way to know which file types are associated with which apps. On macOS this is done in the plist file included inside the application bundle. On Windows this is handled in the Windows Registry.

That tutorial shows how LiveCode can be used to read and write the appropriate Registry entries to associate your unique file type with your application.

Please note it will need to be a unique file type. File type extensions matter to the OS, but not to the LC engine. The engine can open any valid LC stack file regardless of its file extension.

When opening from within LC this is simple and automatic; scripting "open stack <file path> just works.

It's the part involving the Windows File Explorer, either dragging your document file icon to the app or double clicking it, where the appropriate Registry entry is needed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: launching livecode files in Windows in one instance of LiveCode

Post by SparkOut » Sat Oct 05, 2024 8:02 pm

Unless I am misreading, I think the file association is fine.
Double-clicking a file with (eg) extension of .rev will open that file in the IDE.
The problem for the OP is that once opened in the IDE, then double-clicking the same file will also open it, in a new instance of the IDE.
What should normally happen, I believe, is that the original instance of the IDE would attempt to open the file, but halt with a prompt to the user advising a stack with that name is already open, and to choose whether to close, or purge the original.
I don't know why two IDE instances would be initiated.

Post Reply