Skip to content

Introduce Platform.style-name and Platform.os #8202

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

Merged
merged 2 commits into from
May 6, 2025
Merged

Conversation

tronical
Copy link
Member

@tronical tronical commented Apr 18, 2025

This replaces the previously hidden StyleMetrics.style-name that was only accessible for internal use, introduced in #8200.

Additionally, this introduces Platform.os.

@tronical
Copy link
Member Author

I tried this manually, but I'm curious about suggestions how to test this. I could "expose" Platform.style-name via property to a test's native code, but then... how to verify that the value is "correct"? I guess I can at least check that it's not empty.

@tronical tronical force-pushed the simon/platform-global branch from 0895f51 to 7e66928 Compare April 18, 2025 14:07
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks good to me.

But I don't think we should have Platform without the other stuff like os and stuff. and it's probably not a good idea to rush that in 1.11 so i'd favor waiting.

For the test, maybe you can have something like
out property <bool> test: Platform.style-name != "" && (Platform.os == "macOs" ? platform.style-name == "cupertino" : Platform.os == "windows" ? platform.style-name == "fluent" : true );

or out property <string> style-name <=> Platform.style-name (i wonder if <=> is allowed actually, otherwise just use :) and test that with #[cfg(...)] in the rust test.

For the name, should it be style-name or just style ?

@@ -840,7 +840,7 @@ impl Snapshotter {
pub struct TypeLoader {
pub global_type_registry: Rc<RefCell<TypeRegister>>,
pub compiler_config: CompilerConfiguration,
style: String,
pub resolved_style: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have left the name as is. But can't hurt.
Maybe a doc comment explaining what is is exactly would be good.

@tronical
Copy link
Member Author

But I don't think we should have Platform without the other stuff like os and stuff.

That sounds good to me. I'll add those "on top" in this PR then.

and it's probably not a good idea to rush that in 1.11 so i'd favor waiting.

Absolutely. I don't intend to propose this for 1.11. As discussed in the API review, I just wanted to do both in one, the change for 1.11 as well as the follow-up, so that it's clearer to see where this goes.

For the test, maybe you can have something like out property <bool> test: Platform.style-name != "" && (Platform.os == "macOs" ? platform.style-name == "cupertino" : Platform.os == "windows" ? platform.style-name == "fluent" : true );

or out property <string> style-name <=> Platform.style-name (i wonder if <=> is allowed actually, otherwise just use :) and test that with #[cfg(...)] in the rust test.

Ah yes, great, with os then it makes sense.

For the name, should it be style-name or just style ?

I prefer style-name. I'd go with that for now and we can review it once more for 1.12 ;-)

@tronical tronical marked this pull request as draft April 19, 2025 07:27
@tronical
Copy link
Member Author

Marking this as draft, to make it clearer that I don't intend this for 1.11.

@tronical
Copy link
Member Author

out property test: Platform.style-name != "" && (Platform.os == "macOs" ? platform.style-name == "cupertino" : Platform.os == "windows" ? platform.style-name == "fluent" : true );

Oops, I see that this doesn't work because we go through lengths to make sure that tests are run with the fluent style for consistent results :-). But I'll add this to the widget tests and check at least that the value changes.

@tronical tronical force-pushed the simon/platform-global branch 2 times, most recently from fb87cb5 to affe667 Compare April 19, 2025 09:01
@tronical tronical changed the title Introduce Platform.style-name Introduce Platform.style-name and Platform.os Apr 19, 2025
This replaces the previously hidden `StyleMetrics.style-name` that was only accessible for internal use.
@tronical tronical force-pushed the simon/platform-global branch from 9cb1f8b to 534e935 Compare April 28, 2025 14:47
@tronical tronical marked this pull request as ready for review April 28, 2025 14:47
| macOS | `macos` |
| Linux | `linux` |
| Android | `android` |
| iOS | `iOS` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"iOs" as a uppercase O, should macOs too? and Windows and Linux and Android?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, the values are intended to be lower-case. I'll fix that.

| Android | `android` |
| iOS | `iOS` |

If the operating system is none of the above, the value of this property is the empty string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note that more values may be added in the future.

I wonder if we should make it an enum.

Also i imagine our user would also want to distinguish between the web and native. We should document that when running on wasm, this does a runtime check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note that more values may be added in the future.

Ok

Also i imagine our user would also want to distinguish between the web and native. We should document that when running on wasm, this does a runtime check.

I can add that in the docs.

For WASM, we could also add a Platform.is-web-assembly or so (not this particular name maybe, but a boolean - I'm open to suggestions here)

@tronical tronical force-pushed the simon/platform-global branch from e6f0c29 to a7b0a63 Compare May 6, 2025 11:06
@tronical tronical merged commit f983cf0 into master May 6, 2025
4 checks passed
@tronical tronical deleted the simon/platform-global branch May 6, 2025 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants