firstrun.js (6411B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const lazy = {}; 6 const { topChromeWindow } = window.browsingContext; 7 8 ChromeUtils.defineESModuleGetters(lazy, { 9 AboutWelcomeParent: "resource:///actors/AboutWelcomeParent.sys.mjs", 10 AIWindow: 11 "moz-src:///browser/components/aiwindow/ui/modules/AIWindow.sys.mjs", 12 }); 13 const MODEL_PREF = "browser.aiwindow.firstrun.modelChoice"; 14 const AUTO_ADVANCE_PREF = "browser.aiwindow.firstrun.autoAdvanceMS"; 15 const BRAND_DARK_PURPLE = "#210340"; 16 17 const autoAdvanceMS = Services.prefs.getIntPref(AUTO_ADVANCE_PREF); 18 19 const AI_WINDOW_CONFIG = { 20 id: "AI_WINDOW_WELCOME", 21 template: "spotlight", 22 transitions: true, 23 modal: "tab", 24 backdrop: "transparent", 25 screens: [ 26 { 27 id: "AI_WINDOW_INTRO", 28 auto_advance: { 29 actionEl: "primary_button", 30 actionTimeMS: autoAdvanceMS, 31 }, 32 force_hide_steps_indicator: true, 33 content: { 34 fullscreen: true, 35 hide_secondary_section: "responsive", 36 position: "center", 37 paddingBottom: "0px", 38 background: "transparent", 39 screen_style: { 40 overflow: "hidden", 41 }, 42 title: { 43 fontWeight: 350, 44 fontSize: "39px", 45 letterSpacing: 0, 46 lineHeight: "56px", 47 textAlign: "center", 48 string_id: "aiwindow-firstrun-title", 49 }, 50 primary_button: { 51 label: "", 52 action: { 53 navigate: true, 54 }, 55 }, 56 }, 57 }, 58 { 59 id: "AI_WINDOW_CHOOSE_MODEL", 60 force_hide_steps_indicator: true, 61 content: { 62 position: "center", 63 background: "transparent", 64 screen_style: { 65 width: "750px", 66 }, 67 title: { 68 string_id: "aiwindow-firstrun-model-title", 69 fontSize: "40px", 70 fontWeight: "350", 71 letterSpacing: 0, 72 lineHeight: "normal", 73 }, 74 subtitle: { 75 string_id: "aiwindow-firstrun-model-subtitle", 76 fontSize: "17px", 77 fontWeight: 320, 78 color: BRAND_DARK_PURPLE, 79 }, 80 tiles: { 81 type: "single-select", 82 selected: "none", 83 autoTrigger: false, 84 action: { 85 picker: "<event>", 86 }, 87 data: [ 88 { 89 id: "model_1", 90 label: { 91 string_id: "aiwindow-firstrun-model-fast-label", 92 fontSize: "20px", 93 fontWeight: 613, 94 color: BRAND_DARK_PURPLE, 95 }, 96 icon: { 97 background: 98 'center / contain no-repeat url("chrome://browser/content/aiwindow/assets/model-choice-1.svg")', 99 }, 100 body: { 101 string_id: "aiwindow-firstrun-model-fast-body", 102 color: BRAND_DARK_PURPLE, 103 fontSize: "15px", 104 fontWeight: 320, 105 }, 106 action: { 107 type: "SET_PREF", 108 data: { 109 pref: { 110 name: MODEL_PREF, 111 value: "1", 112 }, 113 }, 114 }, 115 }, 116 { 117 id: "model_2", 118 label: { 119 string_id: "aiwindow-firstrun-model-allpurpose-label", 120 fontSize: "20px", 121 fontWeight: 613, 122 color: BRAND_DARK_PURPLE, 123 }, 124 icon: { 125 background: 126 'center / contain no-repeat url("chrome://browser/content/aiwindow/assets/model-choice-2.svg")', 127 }, 128 body: { 129 string_id: "aiwindow-firstrun-model-allpurpose-body", 130 color: BRAND_DARK_PURPLE, 131 fontSize: "15px", 132 fontWeight: 320, 133 }, 134 action: { 135 type: "SET_PREF", 136 data: { 137 pref: { 138 name: MODEL_PREF, 139 value: "2", 140 }, 141 }, 142 }, 143 }, 144 { 145 id: "model_3", 146 label: { 147 string_id: "aiwindow-firstrun-model-personal-label", 148 fontSize: "20px", 149 fontWeight: 613, 150 color: BRAND_DARK_PURPLE, 151 }, 152 icon: { 153 background: 154 'center / contain no-repeat url("chrome://browser/content/aiwindow/assets/model-choice-3.svg")', 155 }, 156 body: { 157 string_id: "aiwindow-firstrun-model-personal-body", 158 color: BRAND_DARK_PURPLE, 159 fontSize: "15px", 160 fontWeight: 320, 161 }, 162 action: { 163 type: "SET_PREF", 164 data: { 165 pref: { 166 name: MODEL_PREF, 167 value: "3", 168 }, 169 }, 170 }, 171 }, 172 ], 173 }, 174 primary_button: { 175 label: { 176 string_id: "aiwindow-firstrun-button", 177 }, 178 action: { 179 navigate: true, 180 }, 181 }, 182 }, 183 }, 184 ], 185 }; 186 187 function renderFirstRun() { 188 const AWParent = new lazy.AboutWelcomeParent(); 189 const receive = name => data => 190 AWParent.onContentMessage( 191 `AWPage:${name}`, 192 data, 193 topChromeWindow.gBrowser.selectedBrowser 194 ); 195 196 window.AWGetFeatureConfig = () => AI_WINDOW_CONFIG; 197 window.AWEvaluateScreenTargeting = screens => screens; 198 window.AWGetSelectedTheme = () => ({}); 199 window.AWGetInstalledAddons = () => []; 200 window.AWSendToParent = (name, data) => receive(name)(data); 201 window.AWFinish = () => { 202 window.location.href = lazy.AIWindow.newTabURL; 203 }; 204 205 window.addEventListener( 206 "unload", 207 () => { 208 AWParent.didDestroy(); 209 }, 210 { once: true } 211 ); 212 213 const script = document.createElement("script"); 214 script.src = "chrome://browser/content/aboutwelcome/aboutwelcome.bundle.js"; 215 document.body.appendChild(script); 216 } 217 218 if (document.readyState === "loading") { 219 document.addEventListener("DOMContentLoaded", renderFirstRun, { once: true }); 220 } else { 221 renderFirstRun(); 222 }