You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2019/03/13 17:22:05 UTC

[royale-asjs] branch develop updated: OSUtils: add getOSVersion method

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1cdbf22  OSUtils: add getOSVersion method
1cdbf22 is described below

commit 1cdbf22ac15b37d60fa658fd93eef4feaba2f8bf
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Wed Mar 13 18:21:57 2019 +0100

    OSUtils: add getOSVersion method
---
 .../main/royale/org/apache/royale/utils/OSUtils.as | 59 +++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/OSUtils.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/OSUtils.as
index ce07753..4456791 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/OSUtils.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/OSUtils.as
@@ -47,6 +47,8 @@ package org.apache.royale.utils
         public static const ANDROID_OS:String = "Android";
         public static const IOS_OS:String = "iOS";
         public static const UNKNOWN_OS:String = "Unknown OS";
+        
+        public static const UNKNOWN_VERSION:String = "Unknown OS Version";
 
         /**
          * Gets the name of the operating system.
@@ -85,7 +87,62 @@ package org.apache.royale.utils
                 return _osName;
             }
         }
-        
+
         private static var _osName:String;
+
+        /**
+         * Gets the version of the operating system.
+         */
+        public static function getOSVersion():String
+        {
+            COMPILE::SWF
+            {
+            if(!_osVersion)
+            {
+                _osVersion = "To be implemented in SWF";
+            }
+            return _osVersion;
+            }
+
+            COMPILE::JS
+            {
+            if(!_osVersion)
+            {
+                var tokenizer:Array = navigator.userAgent.split(/\s*[;)(]\s*/);
+                _osVersion = UNKNOWN_VERSION;
+                if (/^Android/.test(tokenizer[2]))
+                {
+                    _osVersion = tokenizer[2].split("Android ").pop(); // "8.1.0"
+                }
+                else if (/^Linux/.test(tokenizer[3]))
+                {
+                    _osVersion = tokenizer[6].split("/").pop(); // "8.10" (Ubuntu)
+                }
+                else if (/^Macintosh/.test(tokenizer[1]))
+                {
+                    _osVersion = tokenizer[2].split("Mac OS X ").pop().replace(/_/g,'.'); // "10.8.2" (Mountain Lion)
+                }
+                else if (/^iPhone/.test(tokenizer[1]))
+                {
+                    _osVersion = tokenizer[2].split("CPU iPhone OS ").pop().replace(/_/g,'.').replace(' like Mac OS X',''); // "12.1.4"
+                }
+                else if (/^iPad/.test(tokenizer[1]))
+                {
+                    _osVersion = tokenizer[2].split("CPU OS ").pop().replace(/_/g,'.').replace(' like Mac OS X',''); // "12.1.4"
+                }
+                else if (/^iPod/.test(tokenizer[1]))
+                {
+                    _osVersion = tokenizer[2].split("CPU OS ").pop().replace(/_/g,'.').replace(' like Mac OS X',''); // "12.1.4" (this one needs test)
+                }
+                else
+                {
+                    _osVersion = tokenizer[3].split(" ").pop(); // "6.1" (Win 7)
+                }
+            }
+            return _osVersion;
+            }
+        }
+
+        private static var _osVersion:String;
     }
 }