diff --git a/apps/common/mobile/lib/controller/Themes.js b/apps/common/mobile/lib/controller/Themes.js index 5e9d9bfc6..dffe5de0a 100644 --- a/apps/common/mobile/lib/controller/Themes.js +++ b/apps/common/mobile/lib/controller/Themes.js @@ -12,7 +12,9 @@ class ThemesController { id: 'theme-light', type: 'light' }}; + } + init() { const obj = LocalStorage.getItem("ui-theme"); let theme = this.themes_map.light; if ( !!obj ) @@ -23,10 +25,7 @@ class ThemesController { LocalStorage.setItem("ui-theme", JSON.stringify(theme)); } - const $$ = Dom7; - const $body = $$('body'); - $body.attr('class') && $body.attr('class', $body.attr('class').replace(/\s?theme-type-(?:dark|light)/, '')); - $body.addClass(`theme-type-${theme.type}`); + this.switchDarkTheme(theme, true); } get isCurrentDark() { @@ -35,12 +34,23 @@ class ThemesController { } switchDarkTheme(dark) { - const theme = this.themes_map[dark ? 'dark' : 'light']; - LocalStorage.setItem("ui-theme", JSON.stringify(theme)); + const theme = typeof dark == 'object' ? dark : this.themes_map[dark ? 'dark' : 'light']; + const refresh_only = !!arguments[1]; + + if ( !refresh_only ) + LocalStorage.setItem("ui-theme", JSON.stringify(theme)); const $body = $$('body'); $body.attr('class') && $body.attr('class', $body.attr('class').replace(/\s?theme-type-(?:dark|light)/, '')); $body.addClass(`theme-type-${theme.type}`); + + const on_engine_created = api => { + api.asc_setSkin(theme.id); + }; + + const api = Common.EditorApi ? Common.EditorApi.get() : undefined; + if(!api) Common.Notifications.on('engineCreated', on_engine_created); + else on_engine_created(api); } } diff --git a/apps/documenteditor/mobile/src/view/app.jsx b/apps/documenteditor/mobile/src/view/app.jsx index 02821f8a5..57805e0cb 100644 --- a/apps/documenteditor/mobile/src/view/app.jsx +++ b/apps/documenteditor/mobile/src/view/app.jsx @@ -13,6 +13,7 @@ import routes from '../router/routes'; import Notifications from '../../../../common/mobile/utils/notifications.js' import {MainController} from '../controller/Main'; import {Device} from '../../../../common/mobile/utils/device' +import {Themes} from '../../../../common/mobile/lib/controller/Themes' const f7params = { name: 'Desktop Editor', // App name @@ -26,6 +27,7 @@ export default class extends React.Component { super(props); Common.Notifications = new Notifications(); + Themes.init(); } render() { diff --git a/apps/presentationeditor/mobile/src/page/app.jsx b/apps/presentationeditor/mobile/src/page/app.jsx index 699cdcc8f..3fe415359 100644 --- a/apps/presentationeditor/mobile/src/page/app.jsx +++ b/apps/presentationeditor/mobile/src/page/app.jsx @@ -13,6 +13,7 @@ import routes from '../router/routes.js'; import Notifications from '../../../../common/mobile/utils/notifications.js' import {MainController} from '../controller/Main'; import {Device} from '../../../../common/mobile/utils/device' +import {Themes} from '../../../../common/mobile/lib/controller/Themes' // Framework7 Parameters const f7params = { @@ -27,6 +28,7 @@ export default class extends React.Component { super(); Common.Notifications = new Notifications(); + Themes.init(); } render() { diff --git a/apps/spreadsheeteditor/mobile/src/page/app.jsx b/apps/spreadsheeteditor/mobile/src/page/app.jsx index 44da854e1..02bd3f4f0 100644 --- a/apps/spreadsheeteditor/mobile/src/page/app.jsx +++ b/apps/spreadsheeteditor/mobile/src/page/app.jsx @@ -17,6 +17,7 @@ import Notifications from '../../../../common/mobile/utils/notifications.js'; import {MainController} from '../controller/Main'; import {Device} from '../../../../common/mobile/utils/device'; import CellEditor from '../controller/CellEditor'; +import {Themes} from '../../../../common/mobile/lib/controller/Themes' const f7params = { name: 'Spreadsheet Editor', // App name @@ -31,6 +32,7 @@ export default class extends React.Component { Common.Notifications = new Notifications(); Common.localStorage = LocalStorage; + Themes.init(); } render() {