Is plugin running?

• Feb 12, 2016 - 09:58

Is there a way to find out is plugin running?
To prevent the situation on the picture.

   if (myPlugingIsRunning ()) Qt.quit();

Attachment Size
Ms_multiPlug.jpg 68.23 KB


I don't believe there really is at the moment.
Adding a singleton property to a plugin and have MuseScore track the instances might be a future option (feature request).

As a probably workaround (untested, just sprouting the idea here) you could try the following:
* have a Settings object with an alreadyRunning property
* as one of the first things in onRun, check for the property to be false
* if it is true do a Qt.quit(); (perhaps show a warning first?)
* next set that property to true and save it
* make sure to set the property to false again in each possible path that quits your plugin.

In reply to by jeetee

Thank you for idea, jeetee!
Unfortunately for now I don't know how to save Setting not automatically at program quit but when I want. And how to use Setting for saving not properties, but variables. ( )
  Settings {
    id: settings
    category: "myPlugin"
    property alias alreadyRunning : ???

In reply to by straannick

Just discovered that the settings are written each time you change a For this item you should be able to do:

Settings {
    id: settings
    category: "myPlugin"
    property bool alreadyRunning: false //default value if settings didn't exist
onRun: {
    if (settings.alreadyRunning) {
        console.log('myPlugin is already running!);
    settings.alreadyRunning = true; //this is directly saved into the .ini-file

    //do plugin stuff

    settings.alreadyRunning = false; //don't forget do clear this flag just before quitting

In reply to by [DELETED] 5

In the example the category was set as an example to "myPlugin". It would indeed be the idea to fill that out with the actual Plugin identifier like a condensed name or the like.

If that is set, a separate group [myPlugin] is created in the .ini file. According to the Qt docs, that should act as a namespace:
Instead of ensuring that all settings in the application have unique names, the settings can be divided into unique categories that may then contain settings using the same names that are used in other categories - without a conflict.

So let me stress this point here again for everyone using Settings in Plugins: make sure to set the category property to a unique string (like your plugin name).

EDIT: a task has been created to add/improve auto-namespacing for plugin settings #98381: Force a category for the Settings of a Plugin

Do you still have an unanswered question? Please log in first to post your question.