(id, init)
| 79 | * @param {boolean} init Whether or not this is the first time the theme is being applied |
| 80 | */ |
| 81 | export async function apply(id, init) { |
| 82 | if (!DOES_SUPPORT_THEME) { |
| 83 | id = "default"; |
| 84 | } |
| 85 | |
| 86 | themeApplied = true; |
| 87 | const theme = get(id); |
| 88 | const $style = document.head.get("style#app-theme") ?? ( |
| 89 | <style id="app-theme"></style> |
| 90 | ); |
| 91 | const update = { |
| 92 | appTheme: id, |
| 93 | }; |
| 94 | |
| 95 | if (id === "custom") { |
| 96 | update.customTheme = theme.toJSON(); |
| 97 | } |
| 98 | |
| 99 | if (init && theme.preferredEditorTheme) { |
| 100 | update.editorTheme = theme.preferredEditorTheme; |
| 101 | if (editorManager != null && editorManager.editor != null) { |
| 102 | editorManager.editor.setTheme(theme.preferredEditorTheme); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (init && theme.preferredFont) { |
| 107 | update.editorFont = theme.preferredFont; |
| 108 | fonts.setFont(theme.preferredFont); |
| 109 | } |
| 110 | |
| 111 | if (init && firstTime && theme.preferredTerminalTheme) { |
| 112 | update.terminalSettings = { |
| 113 | ...(settings.value.terminalSettings || {}), |
| 114 | theme: theme.preferredTerminalTheme, |
| 115 | }; |
| 116 | } |
| 117 | |
| 118 | settings.update(update, false); |
| 119 | |
| 120 | if (init && firstTime && theme.preferredTerminalTheme) { |
| 121 | if (editorManager != null) { |
| 122 | updateActiveTerminals("theme", theme.preferredTerminalTheme); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | localStorage.__primary_color = theme.primaryColor; |
| 127 | document.body.setAttribute("theme-type", theme.type); |
| 128 | $style.textContent = theme.css; |
| 129 | document.head.append($style); |
| 130 | |
| 131 | const primaryColor = color(theme.primaryColor).hex.toString(); |
| 132 | const scheme = theme.toJSON("hex"); |
| 133 | // Set status bar and navigation bar color |
| 134 | system.setUiTheme(primaryColor, scheme); |
| 135 | |
| 136 | if (firstTime) { |
| 137 | // To make sure system bars are updated |
| 138 | setTimeout(() => { |
no test coverage detected