Skip to content

Commit

Permalink
[desktop] skip to send theme changing event to native
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkadushkin committed Mar 19, 2024
1 parent 2f32ed3 commit 46941e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
27 changes: 18 additions & 9 deletions apps/common/main/lib/controller/Desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions apps/common/main/lib/controller/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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));
},
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
},
Expand Down

0 comments on commit 46941e6

Please sign in to comment.