Do you mean you have let's say 10 flows using 10 triggers which has empty text filter? And when there is a single toast message appear (notification on screen), all those 10 flows got triggered and executed?
If yes, that is not efficient. Because single toast will execute 10 flows, and do 10 check (not counting the script global lock delay).
You should just remove all of the Notification on Screen triggers from all of the flows. And the put that into single flow only, prefer to separate flow first (the 11th flow). So each time toast message appear, only this flow got executed, and checked according to your regex upon you glovar list.
When I see your structure, it seems you have several commands and separated based on the function. Each function can have multiple commands to execute the parent function. So "Play Music", "Play Songs", "Sing a song" will trigger "Play Music" flow. I assume you do the loop to compare the toast message against each of the element from 0.0, 0.1, 0.2 and so on until it finished. And when something found, you would use the parents 0. or 1. or 2. as the command detected.
Each toast will always correspond to single command. And some toasts can refer to the same command. I would prefer to store them into a single level glovar Map only and use multiple keys to refer to the same value. It is easier to store and maintain compared to a nested 2 level list (and you even separate them again to different glovar). So you don't need the glovar one and two anymore. It is even better if you can simply redirect it to the flow name you want, so each command is the flow name to execute. Simply store them like this.
Code: Select all
global_command_database = newMapFromValues(
"play music", "play music",
"play songs", "play music",
"sing a song", "play music",
"mute", "pause",
"shut up", "pause",
"mute", "puase",
"play next", "next music",
"another music", "next music",
"another song", "next music",
"turn on wifi", "wifi on",
"wifi please", "wifi on",
"turn off wifi", "wifi off",
"stop the wifi", "wifi off",
"is my wifi on or off", "wifi status");
In the end, you have a single database center contain all the possible command in the key map, and all of the executed flow name in the value. Some different commands can correspond to the same value, thus executing the same flow. I use all lower case, since I know you are going to use it in speech recognition. All speech recognition matching should be converted to lowercase to avoid case mismatch. When the toast match "sing a song", it will proceed on to execute the flow named "play music". Of course, you have to setup the flow before and prepare the logical flow name.