From 46941e673c7a264c113a4780d113f1a63417b1e6 Mon Sep 17 00:00:00 2001 From: maxkadushkin Date: Tue, 19 Mar 2024 20:55:09 +0300 Subject: [PATCH] [desktop] skip to send theme changing event to native --- apps/common/main/lib/controller/Desktop.js | 27 ++++++++++++++-------- apps/common/main/lib/controller/Themes.js | 10 ++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/common/main/lib/controller/Desktop.js b/apps/common/main/lib/controller/Desktop.js index 1c51805d95..c81a099bbd 100644 --- a/apps/common/main/lib/controller/Desktop.js +++ b/apps/common/main/lib/controller/Desktop.js @@ -48,6 +48,10 @@ define([ uithemes: true, btnhome: true, quickprint: true, + framesize: { + width: window.innerWidth, + height: window.innerHeight + }, }, webapp.features); var native = window.desktop || window.AscDesktopEditor; @@ -139,7 +143,7 @@ define([ } } else if (/theme:changed/.test(cmd)) { - Common.UI.Themes.setTheme(param); + Common.UI.Themes.setTheme(param, "native"); } else if (/^uitheme:added/.test(cmd)) { if ( !nativevars.localthemes ) @@ -169,7 +173,7 @@ define([ window.RendererProcessVariable.theme.system = opts.theme.system; if ( Common.UI.Themes.currentThemeId() == 'theme-system' ) - Common.UI.Themes.refreshTheme(true); + Common.UI.Themes.refreshTheme(true, 'native'); } } else if (/element:show/.test(cmd)) { @@ -557,13 +561,18 @@ define([ 'modal:show': _onModalDialog.bind(this, 'open'), 'modal:close': _onModalDialog.bind(this, 'close'), 'modal:hide': _onModalDialog.bind(this, 'hide'), - 'uitheme:changed' : function (name) { - if ( window.uitheme.is_theme_system() ) { - native.execCommand("uitheme:changed", JSON.stringify({name:'theme-system'})); - } else { - var theme = Common.UI.Themes.get(name); - if ( theme ) - native.execCommand("uitheme:changed", JSON.stringify({name:name, type:theme.type})); + 'uitheme:changed' : function (name, caller) { + if ( caller != 'native' ) { + if (window.uitheme.is_theme_system()) { + native.execCommand("uitheme:changed", JSON.stringify({name: 'theme-system'})); + } else { + var theme = Common.UI.Themes.get(name); + if (theme) + native.execCommand("uitheme:changed", JSON.stringify({ + name: name, + type: theme.type + })); + } } }, 'hints:show': _onHintsShow.bind(this), diff --git a/apps/common/main/lib/controller/Themes.js b/apps/common/main/lib/controller/Themes.js index 407424a028..f279f48a58 100644 --- a/apps/common/main/lib/controller/Themes.js +++ b/apps/common/main/lib/controller/Themes.js @@ -387,13 +387,13 @@ define([ } } - const refresh_theme = function (force) { + const refresh_theme = function (force, caller) { if ( force || Common.localStorage.getItem('ui-theme-id') != window.uitheme.id ) { const theme_id = Common.localStorage.getItem('ui-theme-id'); if ( theme_id ) { apply_theme.call(this, theme_id); - Common.NotificationCenter.trigger('uitheme:changed', theme_id); + Common.NotificationCenter.trigger('uitheme:changed', theme_id, caller); } } } @@ -427,7 +427,7 @@ define([ if ( !document.body.classList.contains('theme-type-' + obj.type) ) document.body.classList.add('theme-type-' + obj.type); - if ( !(Common.Utils.isIE10 || Common.Utils.isIE11) ) + if ( !(Common.Utils.isIE10 || Common.Utils.isIE11) && !Common.Controllers.Desktop.isActive() ) window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', on_system_theme_dark.bind(this)); Common.NotificationCenter.on('document:ready', on_document_ready.bind(this)); }, @@ -503,7 +503,7 @@ define([ Common.NotificationCenter.trigger('contenttheme:dark', window.uitheme.iscontentdark); }, - setTheme: function (obj) { + setTheme: function (obj, caller) { if ( !obj ) return; const id = get_ui_theme_name(obj); @@ -512,7 +512,7 @@ define([ apply_theme.call(this, id); Common.localStorage.setItem('ui-theme-id', id); - Common.NotificationCenter.trigger('uitheme:changed', id); + Common.NotificationCenter.trigger('uitheme:changed', id, caller); } } },