From 3636bf78c4bd2e05f180b66b82000f4ceac2c9e4 Mon Sep 17 00:00:00 2001
From: Maxim Kadushkin <maxim.kadushkin@onlyoffice.com>
Date: Fri, 12 Feb 2021 12:08:33 +0300
Subject: [PATCH] [all] fix for device scaling checking

---
 apps/common/main/lib/util/utils.js  | 18 +++++++++++++++++-
 apps/documenteditor/main/app.js     |  1 +
 apps/presentationeditor/main/app.js |  1 +
 apps/spreadsheeteditor/main/app.js  |  1 +
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js
index 6a0eec4e7..de1210325 100644
--- a/apps/common/main/lib/util/utils.js
+++ b/apps/common/main/lib/util/utils.js
@@ -119,7 +119,23 @@ Common.Utils = _.extend(new(function() {
         isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent || navigator.vendor || window.opera),
         me = this,
         checkSize = function() {
-            var scale = window.AscCommon.checkDeviceScale();
+            var scale = {};
+            if ( !!window.AscCommon )
+                scale = window.AscCommon.checkDeviceScale();
+            else {
+                var str_mq_150 = "screen and (-webkit-min-device-pixel-ratio: 1.5) and (-webkit-max-device-pixel-ratio: 1.9), " +
+                        "screen and (min-resolution: 1.5dppx) and (max-resolution: 1.9dppx)";
+                var str_mq_200 = "screen and (-webkit-min-device-pixel-ratio: 2), " +
+                        "screen and (min-resolution: 2dppx), screen and (min-resolution: 192dpi)";
+
+                if ( window.matchMedia(str_mq_150).matches ) {
+                    scale.devicePixelRatio = 1.5;
+                } else
+                if ( window.matchMedia(str_mq_200).matches )
+                    scale.devicePixelRatio = 2;
+                else scale.devicePixelRatio = 1;
+            }
+
             var $root = $(document.body);
             if ( scale.devicePixelRatio > 1 && scale.devicePixelRatio <= 1.5 ) {
                 $root.removeClass('pixel-ratio__2');
diff --git a/apps/documenteditor/main/app.js b/apps/documenteditor/main/app.js
index 0de0c48a2..8ea061937 100644
--- a/apps/documenteditor/main/app.js
+++ b/apps/documenteditor/main/app.js
@@ -207,6 +207,7 @@ require([
                 ,'common/main/lib/controller/Protection'
                 ,'common/main/lib/controller/Themes'
                 ,'common/main/lib/controller/Desktop'
+                ,'../../../../sdkjs/common/device_scale.js'
             ], function() {
                 app.start();
             });
diff --git a/apps/presentationeditor/main/app.js b/apps/presentationeditor/main/app.js
index 5fb88c9ff..8d216f902 100644
--- a/apps/presentationeditor/main/app.js
+++ b/apps/presentationeditor/main/app.js
@@ -191,6 +191,7 @@ require([
             ,'common/main/lib/controller/Protection'
             ,'common/main/lib/controller/Themes'
             ,'common/main/lib/controller/Desktop'
+            ,'../../../../sdkjs/common/device_scale.js'
         ], function() {
             app.start();
         });
diff --git a/apps/spreadsheeteditor/main/app.js b/apps/spreadsheeteditor/main/app.js
index 2057534be..f9893f9cd 100644
--- a/apps/spreadsheeteditor/main/app.js
+++ b/apps/spreadsheeteditor/main/app.js
@@ -203,6 +203,7 @@ require([
             ,'common/main/lib/controller/Protection'
             ,'common/main/lib/controller/Themes'
             ,'common/main/lib/controller/Desktop'
+            ,'../../../../sdkjs/common/device_scale.js'
         ], function() {
             app.start();
         });