From 08b7b28149e630d28190e2139daff19bba330b99 Mon Sep 17 00:00:00 2001 From: Johnny A <5891646+johnny243@users.noreply.github.com> Date: Tue, 17 May 2022 10:51:45 -0400 Subject: [PATCH] fix: crash when using a 3rd-party theme with native features (#615) * fix: crash when using a 3rd-party theme with native features * fix: preload 3rd-party theme from ThemeService * fix: take preloadThirdPartyThemeIndexPath outside of setActiveTheme * fix: move preloadThirdPartyThemeIndexPath to component manager Co-authored-by: Johnny Almonte --- src/Lib/ComponentManager.ts | 16 ++++++++++++++-- src/Style/ThemeService.ts | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Lib/ComponentManager.ts b/src/Lib/ComponentManager.ts index 6561d779..5482ca49 100644 --- a/src/Lib/ComponentManager.ts +++ b/src/Lib/ComponentManager.ts @@ -64,8 +64,8 @@ export class ComponentManager extends SNComponentManager { } catch (e) { void this.alertService.alert( 'Unable to start component server. ' + - 'Editors other than the Plain Editor will fail to load. ' + - 'Please restart the app and try again.' + 'Editors other than the Plain Editor will fail to load. ' + + 'Please restart the app and try again.' ) SNLog.error(e as any) } @@ -317,6 +317,18 @@ export class ComponentManager extends SNComponentManager { return [] } } + + public async preloadThirdPartyThemeIndexPath() { + const theme = this.mobileActiveTheme + if (!theme) { + return + } + + const { identifier } = theme + if (this.isComponentThirdParty(identifier)) { + await this.preloadThirdPartyIndexPathFromDisk(identifier) + } + } } export async function associateComponentWithNote(application: SNApplication, component: SNComponent, note: SNNote) { diff --git a/src/Style/ThemeService.ts b/src/Style/ThemeService.ts index 69d82092..3bded8d0 100644 --- a/src/Style/ThemeService.ts +++ b/src/Style/ThemeService.ts @@ -262,6 +262,7 @@ export class ThemeService { const matchingThemeId = Object.keys(this.themes).find(themeId => themeId === savedThemeId) if (matchingThemeId) { this.setActiveTheme(matchingThemeId) + void this.application?.mobileComponentManager.preloadThirdPartyThemeIndexPath() } else { this.setDefaultTheme() }