Background script steals divs/notifications #493
-
|
I tried to create a simple script to time when I sit/stand during work. But unfortunately it appears it's not easyto show UI from background script in a way that do not interfere with main app. When I use 'notify' - it appears to close the script as well Screen.Recording.2021-10-23.at.09.27.18.mp4Example script: // Background: auto
/** @type {import("@johnlindquist/kit")} */
const sitFor = 3000;
const standFor = 3000;
function startStand() {
setTimeout(() => {
div("time to sit!");
startSit();
}, standFor);
}
function startSit() {
setTimeout(() => {
div("time to stand!");
startStand();
}, sitFor);
}
startSit(); |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
One rule I put in place early on: 1 UI = 1 script. So starting a new script always cancels a currently running script in the app. The reason: I don't want Script Kit to accidentally create a ton of runaway processes that could end up crashing the machine (which could be really easy to do with background/watchers/incoming events/etc). SolutionYou should be able to run a script that uses Future SolutionI still plan on adding a "widget" system to spawn multiple UIs that each bind to a specific script (imagine spawning multiple editors, etc). But that's sometime next year. Notes on the script:You should be able to take advantage of while(true){
await wait(3000)
notify(`stand`)
await wait(3000)
notify(`sit`)
} |
Beta Was this translation helpful? Give feedback.
-
|
Ah got it! Thanks for explaining. but it appears that when you call notify from background task - UI of Kit is disappearing. closes.mp4// Thanks for the idea with while + await. I'll share the script once I polish it :) |
Beta Was this translation helpful? Give feedback.
-
|
Idea: clicking on kit icon in top bar - could show some information from background scripts (something like: https://xbarapp.com/) |
Beta Was this translation helpful? Give feedback.
-
|
I finally tracked this down. I'll get the fix in today. Explanation
Based on the metadata you use, it sends along the ProcessType since the app handles each a little diffrently: export declare enum ProcessType {
App = "App",
Background = "Background",
Prompt = "Prompt",
Schedule = "Schedule",
System = "System",
Watch = "Watch"
} |
Beta Was this translation helpful? Give feedback.
One rule I put in place early on: 1 UI = 1 script. So starting a new script always cancels a currently running script in the app.
The reason: I don't want Script Kit to accidentally create a ton of runaway processes that could end up crashing the machine (which could be really easy to do with background/watchers/incoming events/etc).
Solution
You should be able to run a script that uses
notifyin the terminal. Running a script in the terminal doesn't open a channel to the app.Future Solution
I still plan on adding a "widget" system to spawn multiple UIs that each bind to a specific script (imagine spawning multiple editors, etc). But that's sometime next year.
Notes on the script:
You sh…