Is there a programmatic way of determining whether a program is running as a widget or app?
Is there a "has" that will do it?
Is there a programmatic way of determining whether a program is running as a widget or app?
Is there a "has" that will do it?
You might be able to do something like a "has" for ActivityRecording:
if (Toybox has :ActivityRecording) {
//device app
} else {
//widget
}
Thanks.
Hmm. Using that requires an extra permission. It wouldn't be reasonable to add that just for that purpose.
Details: Permission for module 'Toybox.ActivityRecording' required
Maybe you can find something similar that's only available in device apps and not widgets.
Shouldn't the app itself know if it is a data field or not? If so, can't it pass this information down to the layer where you need that information?
The program isn't a data field.
I have the same code being used for an app and a widget.
There a a few places where it might doing make sense doing things differently depending on it being the app or widget.
Are you using (for example) the same AppBase in both the widget and device app? If not, you could set a flag there. Or have a different string in the widget and device app. Just something different between the two.
That's an obvious approach (of course, I'm aware of it). But it's prone to keep breaking since it's something I would need to keep changing (the code is the same for app and widget).
IQ has a general notion of "test for a feature". It's odd that there isn't one for this. (The "test for a feature" doesn't work for glances. I have to exclude the code from devices that don't support it, which is a pain.)
The activity would work but requiring a permission is kind of drastic.
The best way (without the simple test) might be to use exclusions (to include one of two files). The monkey file doesn't change too often.
It's not something you'd need to keep changing if you set a flag in something that's unique between the widget and the device app. The manifest itself would be different, so you could even do something with "name=" and use <myname>+"w" for the widget and <myname>+a" for the device app and check the last character of the name in your code.
That would be a way but I'm not sure if that will work for an already-released app.
And the name of the app shouldn't have to be different.
The project name is different. Maybe, that's the name you are talking about?
No, the AppName. Not the project name. You can change the project name at any time and it doesn't matter. I'd probably use a different AppName for a widget and Device app, as users see that name in the widget loop and list of activities and having the exact same name could confuse users.
Can you just do something in the jungle file, as I'd expect that to be different files with a widget and device app?