Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(core): Utils.isSimulatorOrEmulator #9065

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexziskind1
Copy link

PR Checklist

What is the current behavior?

No function currently exists to allow a check for a simulator or emulator

What is the new behavior?

The new Util function isSimulatorOrEmulator handles this

Fixes/Implements/Closes #9064 .

NathanWalker
NathanWalker previously approved these changes Nov 25, 2020
Copy link
Contributor

@NathanWalker NathanWalker left a comment

Choose a reason for hiding this comment

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

@triniwiz and I will add some extra security detections in this as well. Thanks @alexziskind1 👏

@NathanWalker NathanWalker changed the title implemented new Util function isSimulatorOrEmulator feat(core): Util.isSimulatorOrEmulator Nov 25, 2020
@NathanWalker NathanWalker changed the title feat(core): Util.isSimulatorOrEmulator feat(core): Utils.isSimulatorOrEmulator Nov 25, 2020
Copy link
Contributor

@NathanaelA NathanaelA left a comment

Choose a reason for hiding this comment

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

Why add this? Shouldn't simulator be just !isRealDevice() why add extra bloat to the framework for a unneeded helper function?

Second, even if we really wanted the "helper" function isSimulatorOrEmulator shouldn't it just be return !isRealDevice() so all actual detection code is contained in one function rather than split into two places that could need changes in the future?

@farfromrefug
Copy link
Collaborator

farfromrefug commented Nov 25, 2020

Are you sure that test is enough on android ? I have something like more complex https://github.com/nativescript-community/extendedinfo/blob/master/src/extendedinfo.android.ts#L4
Also you should cache the value
It is a simple Boolean when cached while the test requires a lot more operations

And to.me that name is far too long :) we don't really care about the fact that iios and android don't use the se name convention

@mapo80
Copy link
Contributor

mapo80 commented Nov 25, 2020

@farfromrefug
Copy link
Collaborator

@mapo80
Copy link
Contributor

mapo80 commented Nov 25, 2020

@NathanaelA NathanaelA dismissed NathanWalker’s stale review November 27, 2020 05:45

This is the wrong fix, isRealDevice should be fixed as all places it is being used is a truthy value and the .d.ts shows it is supposed to return a boolean, so the isRealDevice should be fixed not an additional unneeded helper.

@NathanaelA NathanaelA marked this pull request as draft November 27, 2020 05:47
@NathanaelA

This comment was marked as abuse.

@alexziskind1
Copy link
Author

Instead we should add the additional checks that are used by other frameworks/plugins to beef up the detection of a simulator vs real device so the original export function isRealDevice(): boolean; function is correct on both platforms again.

@NathanaelA The reason behind the new function implementation is that it does not present a breaking change. If isRealDevice is fixed then it can lead to breaking changes, since other framework functions (and potentially many client apps) use the result of this call incorrectly. In other words, on iOS when the device is real, it returns paths, which are being used elsewhere - removing this would result in a breaking change.

@alexziskind1
Copy link
Author

Are you sure that test is enough on android ? I have something like more complex https://github.com/nativescript-community/extendedinfo/blob/master/src/extendedinfo.android.ts#L4
Also you should cache the value
It is a simple Boolean when cached while the test requires a lot more operations

And to.me that name is far too long :) we don't really care about the fact that iios and android don't use the se name convention

@farfromrefug perhaps there may be a style guide that states how long function names can be and how specific they need to be, but for now, I don't think there is one. Renaming this is fine as long as it is clear what the function does. Calling the function isEmulator hints at being specific to Android. Calling it isSimulator hints at being specific to iOS. This function name is clear and it relates that it is a cross platform function.

@NathanaelA

This comment was marked as abuse.

@alexziskind1
Copy link
Author

@NathanaelA totally agree with you that isRealDevice should be fixed, but disagree with you that it is not a breaking change. This is a public API and plugins as well as other client apps could be using isRealDevice as it is. If the fix is implemented, then it will break those. This PR is added functionality that will allow isRealDevice usage to continue as is, without breaking anything, but also provide a good step forward for fixing it in the future, as well as providing the needed simulator check right now.

@NathanaelA

This comment was marked as abuse.

@alexziskind1
Copy link
Author

@NathanaelA fair point. However, isRealDevice also returns the opposite of the truth on Android. So therefore it return true when run on an Emulator. This would be a breaking change.

@NathanaelA

This comment was marked as abuse.

@farfromrefug
Copy link
Collaborator

I for one did not even know it was there! I doubt many apps/ plugins use it today

@alexziskind1
Copy link
Author

testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There is no Utility to determine whether current execution is on a simulator or emulator
5 participants