Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20064] Windows: Convert platform-specific (store or phone only) code to using macros to guard

GitHub Issuen/a
TypeStory
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-12-22T17:38:02.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.3.0
ComponentsWindows
Labelsn/a
ReporterChristopher Williams
AssigneeKota Iguchi
Created2015-11-25T18:56:53.000+0000
Updated2016-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)

Comments

  1. Kota Iguchi 2015-12-15

    Turns out #define xxx #if (xxx) is not valid as well as #define xxx #endif. I would simply do
       #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
       
    and
       #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
       #endif
       
  2. Kota Iguchi 2015-12-21

    https://github.com/appcelerator/titanium_mobile_windows/pull/512
  3. Eric Merriman 2016-05-12

    Closing as implemented.

JSON Source