Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Dark Mode On reports opposite first time when ran #190

Open
mkozjak opened this issue Nov 6, 2023 · 28 comments
Open

Is Dark Mode On reports opposite first time when ran #190

mkozjak opened this issue Nov 6, 2023 · 28 comments
Labels
bug Something isn't working

Comments

@mkozjak
Copy link

mkozjak commented Nov 6, 2023

Description

I have an action that I shared here that checks whether Dark Mode is enabled before creating a menu for my Action Button. The first time I run the shortcut after the Dark Mode toggles (either manually or automatically), Is Dark Mode On returns false when dark mode is on and true when it’s off (the opposite of what it should actually be). It is super-simple to reproduce this behavior. Just toggle Dark Mode manually and run the provided shortcut. My menu items will be painted with wrong colors.

It feels like something isn’t refreshing the state that is used by the Is Dark Mode On and is only refreshed after the first time it was queried. Maybe this doesn’t make sense, thought. I have tried running Is Dark Mode On two times in order to try triggering the change and putting Wait after checking the Boolean, but it didn’t help.

Thanks for this great project!

macOS/iOS version

iOS 17.1

Shortcut URL

https://www.icloud.com/shortcuts/6c69d48f302a40e78b6229f86eb86977

@mkozjak mkozjak added the bug Something isn't working label Nov 6, 2023
@mkozjak
Copy link
Author

mkozjak commented Nov 7, 2023

Seems like this is somehow connected to this part of the code. I guess we're not getting an up-to-date information from the OS.

@mkozjak
Copy link
Author

mkozjak commented Nov 7, 2023

I tried running Is Dark Mode On preventively at the top of my shortcut in order to try refreshing the state but it didn’t help.

@rastafaa
Copy link

rastafaa commented Nov 8, 2023

I’ve been having the exact same issue I reported as part of this issue: #180 (comment)

I did briefly describe a workaround that I’ve done for it, at least for the menus. I’ve encountered it in other shortcuts too though which has been annoying. Last I heard the dev wasn’t able to reproduce the issue though unfortunately.. maybe we can help him pinpoint it

@mkozjak
Copy link
Author

mkozjak commented Nov 8, 2023

Yes, I tried applying your workarounds also, @rastafaa, but ultimately the Shortcut started crashing so it's not a solution, unfortunately. :/

@rastafaa
Copy link

rastafaa commented Nov 8, 2023

I actually read the rest of your post now and yeah we both had the same problem of using it to create menu colors, and yeah after first trying the same things you did I did end up finding a workaround that does resolve it. Would be nice to have the bug fixed either way of course

@rastafaa
Copy link

rastafaa commented Nov 8, 2023

Yes, I tried applying your workarounds also, @rastafaa, but ultimately the Shortcut started crashing so it's not a solution, unfortunately. :/

Oh really.. well in that issue I also came up with a way to prevent the crashing (add a 50ms wait before the first menu action)

it hasn’t crashed since then (it’s been several days)

@mkozjak
Copy link
Author

mkozjak commented Nov 8, 2023

Gonna try one more time... Thanks!

@rastafaa
Copy link

rastafaa commented Nov 8, 2023

I see his code comment seems to basically describe the issue, but his solution maybe didn’t fully resolve it. The fact that it’s force-quitting the app probably also explains why my workaround works and also why it crashes.. if it restarts the shortcut before the app has a chance to reload that probably causes it to fail. And also makes sense why adding a short wait resolves the crashing.

“ // iOS does not update the trait collection of apps/extensions that are running in the background, which we are. iOS sometimes reuses the app/extension when running a shortcut a second time, which means it would show outdated values if the dark mode state changed in the meantime. We ensure it always gets a fresh instance by force-quitting the app. Force-quitting the extension made it hang, so it's also important that it's an in-app intent.”

fyi, depending on your device you might need a longer wait.. I’m on 15 pro. So if you have a slower model it might need more time (try 100ms maybe)

@mkozjak
Copy link
Author

mkozjak commented Nov 8, 2023

Same issue goes for Is Silent Mode On... 😔

@mkozjak
Copy link
Author

mkozjak commented Nov 8, 2023

@rastafaa To be honest, your shortcut with the repeat/wait timeout isn't trivial so I don't know how I could apply it to mine.

@rastafaa
Copy link

rastafaa commented Nov 8, 2023

@rastafaa To be honest, your shortcut with the repeat/wait timeout isn't trivial so I don't know how I could apply it to mine.

Here’s a current version of shortcut that activates the dark mode workaround (about midway down) https://www.icloud.com/shortcuts/f5d72357fc6b4e64b91369b75a5d0359

And the actions in that menu: https://www.icloud.com/shortcuts/3ac060e137c8495c93ddde74a5811d6e

And it turns out I put the crash avoider delay into this shortcut: (which is called in the previous shortcut and is what was crashing) https://www.icloud.com/shortcuts/f4770892dd9a4f16b7263c17ad70e6f9

But if it’s too confusing just send a link of yours with the issues and I can try getting it working for you

@mkozjak
Copy link
Author

mkozjak commented Nov 8, 2023

But if it’s too confusing just send a link of yours with the issues and I can try getting it working for you

It's in the first post. Thanks!!

@rastafaa
Copy link

rastafaa commented Nov 9, 2023

But if it’s too confusing just send a link of yours with the issues and I can try getting it working for you

It's in the first post. Thanks!!

Hey I added it to your shortcut, fyi you built it a bit different than me. For changing the menu icon colors I just made a variable that changes white or black depending on appearance value, and then passing that variable to the menu action.. this way you don’t need to duplicate all those actions just to change the color. Suggest trying that in future.

Anyway here’s your shortcut with workaround applied, I didn’t change anything in it except adding my fix and it’s working for me. I did have to move the dark detector to the top to prevent your lock-based items from running twice.

BASE SHORTCUT:
https://www.icloud.com/shortcuts/42e723a092064e1986880dc1de6d547a

SHORTCUT RUNNER:
https://www.icloud.com/shortcuts/6b0c40ff1399468fa2cbb3dc05234dc6

You’ll need to add both of these. The first one replaces the one you currently have. The second one is what you’ll actually use to run the first shortcut. If you run the second on its own it won’t do anything.

@rastafaa
Copy link

rastafaa commented Nov 9, 2023

Also I just realized I think you pass input to this shortcut? That’ll probably cause issues with the workaround so you might need to change it a bit but at least you can see now how it works.

@mkozjak
Copy link
Author

mkozjak commented Nov 9, 2023

Also I just realized I think you pass input to this shortcut? That’ll probably cause issues with the workaround so you might need to change it a bit but at least you can see now how it works.

Nope. No inputs.

Thanks for the patch! TBH, I find writing code in Shortcuts so damn hard that I decided not to refactor it so I left duplications lingering there.

@mkozjak
Copy link
Author

mkozjak commented Nov 15, 2023

@sindresorhus should I try the latest TestFlight release?

@sindresorhus
Copy link
Owner

You can try. I have tried some workaround, but unsure if they actually help.

@mkozjak
Copy link
Author

mkozjak commented Nov 15, 2023

You can try. I have tried some workaround, but unsure if they actually help.

Reverted. There was a bunch of actions missing. For Example, Is Dark Mode On doesn't seem to be available with it. Same for Is Silent Mode On?.

@sindresorhus
Copy link
Owner

@mkozjak You have to restart your device after, because of a Shortcuts bug.

@mkozjak
Copy link
Author

mkozjak commented Nov 15, 2023

The restart didn't help. :/

IMG_9446

Those actions are in the list, though.

image

@sindresorhus
Copy link
Owner

sindresorhus commented Nov 15, 2023

@mkozjak Sorry. There was a bug in the that update that made some actions not work. The latest TestFlight build (55) should correct it.

@mkozjak
Copy link
Author

mkozjak commented Nov 15, 2023

@sindresorhus Ok, this one works. Still the same behaviour in regards to this issue, though, unfortunately.

@mkozjak
Copy link
Author

mkozjak commented Jan 2, 2024

@sindresorhus Any chances this might get fixed with some new update? Thanks!

@sindresorhus
Copy link
Owner

@mkozjak The issue is an iOS bug, so it has to be fixed in an iOS update, not an Actions update.

I have not found a workaround, but the code is open-source, so anyone is free to submit a pull request if they manage to find a workaround.

@rastafaa
Copy link

rastafaa commented Jan 2, 2024

I haven't had the issue since november using my own workarounds.. sorry it didn't work out for you not sure why

@mkozjak
Copy link
Author

mkozjak commented Jan 2, 2024

@rastafaa sorry, you are using the latest testflight release with your workaround?

@rastafaa
Copy link

rastafaa commented Jan 2, 2024

I haven't updated actually because the last time I tried the newer version it ran slower.. so I've been afraid to update lol (can't easily downgrade from an official version without jailbreak)

@rastafaa
Copy link

rastafaa commented Jan 28, 2024

The recent updates completely broke it for me.. it crashes every time dark mode action is ran

I tried beta update because it mentioned bug fixes but now I’m stuck on a version that has broken a lot of my shortcuts :(

edit: got it working again with a delay but things are definitely slower than the older versions

Repository owner deleted a comment from DavideStagni Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants
@sindresorhus @mkozjak @rastafaa and others