= SIGUSR1 = When ladish studio or project is being saved, applications that are run at level 1 receive the SIGUSR1 '''UNIX signal'''. The application, after receiving the signal, should save as soon as possible. However, the saving is not supposed to happen in the signal-handler function itself because signal handlers should be lightweight. For example, you can push a 'Save Event' to your normal event loop. This can be done via global variable: In signal handler function, a global variable can be set to mark that save is needed. On next main loop iteration, the global variable is checked and eventually save is made. The application is free to save [wiki:terms internal state] however it sees fit (e.g. saving files to a fixed file path). When the application is started, some means of restoring the state could to be given to the user, preferably from the commandline. For example, when the signal is received, the application will give a string id (such as a file path) to the user. This id may then be used as a commandline argument to restore the state. = State file = When project file is used for internal state persistence, for the initial creation of the file, two kinds of the workflows are used: The first one assumes that file path supplied through commandline is valid. The workflow is: * user starts the app in ladish without supplying file path at commandline. * optionally, user tweaks internal state * user saves internal state to a file by using app gui * user stops the app * user modifies the commandline used by ladish * user starts the app The second approach assumes that file path supplied through commandline may not exist. The workflow is: * user starts the app in ladish with commandline containing non-existing file path. * on first SIGUSR1 received, the file containing the internal state gets created. The second approach is definitively better from user experience point of view, but it must be implemented carefully because users may expect default behaviour to be to refuse startup when supplied file path is not valid. This is quite common and natural for non-ladish workflows. It will be wise to refuse startup when path does not exist but behave in ladish friendly way if a special commandline option is supplied too. If SIGUSR1 is received but there is no file path supplied, app is free to decide what to do. Best would be to show a "save as" dialog. If this is not possible, user could be informed that save will not be performed. As last possibility, SIGUSR1 can be just ignored and user will have to be more careful. = Examples = There are example implementations [wiki:code_examples here].