[TIMOB-20064] Windows: Convert platform-specific (store or phone only) code to using macros to guard
| GitHub Issue | n/a |
|---|---|
| Type | Story |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2015-12-22T17:38:02.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 5.3.0 |
| Components | Windows |
| Labels | n/a |
| Reporter | Christopher Williams |
| Assignee | Kota Iguchi |
| Created | 2015-11-25T18:56:53.000+0000 |
| Updated | 2016-05-12T17:12:55.000+0000 |
Description
We currently use macros that will effectively compile one block or another depending on whether the code works/is available on phone or desktop.
i.e.
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
This is the right approach for Windows 8, but in Windows 10 a universal app is generated and the check must be done at runtime. We need to convert these checks into a macro and have the macro defined to do different things for 8.1 versus 10.
See https://msdn.microsoft.com/en-us/library/windows/apps/mt188202.aspx and https://msdn.microsoft.com/en-us/library/windows/apps/mt188203.aspx#reviewing_conditional_compilation
I think we can extract a simple macro like:
// Only on Win 8.1
#define PHONE_ONLY_START \
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#define PHONE_ONLY_END \
#endif
// Only on Win 10
#define PHONE_ONLY_START \
if (Windows::System::Profile::AnalyticsInfo::VersionInfo::DeviceFamily == "Windows.Mobile") {
#define PHONE_ONLY_END \
}
We may of course need more variants for things where the API is now available in Win10, but was only available for phone or store on 8.1, etc. (i.e. Clipboard was only for store.desktop in 8.1, but is universal in 10)
Turns out
#define xxx #if (xxx)is not valid as well as#define xxx #endif. I would simply doand#if (WINVER >= 0x0A00) #define IS_WINDOWS_10 #define WINDOWS_PHONE_START if (Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily == "Windows.Mobile") { #define WINDOWS_PHONE_ELSE } else { #define WINDOWS_PHONE_END } #elif (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) #define IS_WINDOWS_PHONE #endif#ifdef IS_WINDOWS_10 WINDOWS_PHONE_START // Windows 10 Mobile specific code WINDOWS_PHONE_ELSE // Windows 10 specific code WINDOWS_PHONE_END #else #ifdef IS_WINDOWS_PHONE // Windows Phone 8.1 specific code #else // Windows 8.1 specific code #endif #endifhttps://github.com/appcelerator/titanium_mobile_windows/pull/512
Closing as implemented.