|
45 | 45 | throw new Error(errorMessage); |
46 | 46 | } |
47 | 47 | console.warn('Make sure to run this following command before starting tests : npm run build '); |
| 48 | + if(window.electronAppAPI) { |
| 49 | + window.__ELECTRON__ = true; |
| 50 | + } |
| 51 | + if(window.__TAURI__ || window.__ELECTRON__) { |
| 52 | + window.__IS_NATIVE_SHELL__ = true; |
| 53 | + } |
48 | 54 | if(window.__TAURI__) { |
49 | 55 | window.testRunnerLogToConsole = function (...args) { |
50 | 56 | const message = args.join(' '); |
|
60 | 66 | } |
61 | 67 | testRunnerLogToConsole(`Tauri test reporters attached.`); |
62 | 68 | } |
| 69 | + if(window.__ELECTRON__) { |
| 70 | + window.testRunnerLogToConsole = function (...args) { |
| 71 | + const message = args.join(' '); |
| 72 | + window.electronAppAPI.consoleLog(message); |
| 73 | + }; |
| 74 | + window.testRunnerErrorToConsole = function (...args) { |
| 75 | + const message = args.join(' '); |
| 76 | + window.electronAppAPI.consoleLog(`ERROR: ${message}`); |
| 77 | + } |
| 78 | + testRunnerLogToConsole(`Electron test reporters attached.`); |
| 79 | + } |
63 | 80 |
|
64 | 81 | // in playwright tests, testRunnerLogToConsole is injected by playwright runners |
65 | 82 |
|
|
143 | 160 | } |
144 | 161 | setupTauriBootVars(); |
145 | 162 | } |
| 163 | + if(window.__ELECTRON__) { |
| 164 | + function setupElectronBootVars() { |
| 165 | + // this is used by storage.js (window.PhStore) to restore our persistent storage layer in electron. |
| 166 | + window._tauriStorageRestorePromise = window.electronFSAPI.appLocalDataDir() |
| 167 | + .then(appDataDir => { |
| 168 | + const sep = window.electronFSAPI.path.sep; |
| 169 | + const storagePath = `${appDataDir}${appDataDir.endsWith(sep) ? "" : sep}storageDB${sep}storageDBDump.json`; |
| 170 | + return window.electronFSAPI.fsReadFile(storagePath); |
| 171 | + }) |
| 172 | + .then(data => { |
| 173 | + if(data && data.__fsError) { |
| 174 | + throw new Error(data.message); |
| 175 | + } |
| 176 | + return data; |
| 177 | + }) |
| 178 | + .catch(err => { |
| 179 | + console.error("First boot detected or Failed to init storage from cache." + |
| 180 | + " If first boot, ignore this error", err); |
| 181 | + }); |
| 182 | + const appNamePromise = window.electronAppAPI.getAppName(); |
| 183 | + // for running tests, the user document dir is set to app data dir as we dont want to |
| 184 | + // corrupt user documents dir for tests |
| 185 | + const documentDirPromise = window.electronFSAPI.appLocalDataDir(); |
| 186 | + const appLocalDirPromise = window.electronFSAPI.appLocalDataDir(); |
| 187 | + const tempDirPromise = window.electronFSAPI.tempDir(); |
| 188 | + window._tauriBootVars = {}; |
| 189 | + const tauriBootStartTime = Date.now(); |
| 190 | + window._tauriBootVarsPromise = Promise.all([appNamePromise, documentDirPromise, |
| 191 | + appLocalDirPromise, tempDirPromise]) |
| 192 | + .then((results) => { |
| 193 | + window._tauriBootVars.appname = results[0]; |
| 194 | + // For tests, documents dir is localAppDataDir/documents to keep user documents garbage free for tests |
| 195 | + window._tauriBootVars.documentDir = results[1]; |
| 196 | + const sep = window.electronFSAPI.path.sep; |
| 197 | + if(!window._tauriBootVars.documentDir.endsWith(sep)){ |
| 198 | + window._tauriBootVars.documentDir = window._tauriBootVars.documentDir + sep; |
| 199 | + } |
| 200 | + window._tauriBootVars.documentDir = `${window._tauriBootVars.documentDir}documents${sep}`; |
| 201 | + //Documents dir special case for tests |
| 202 | + window._tauriBootVars.appLocalDir = results[2]; |
| 203 | + window._tauriBootVars.tempDir = results[3]; |
| 204 | + window._tauriBootVars.bootstrapTime = Date.now() - tauriBootStartTime; |
| 205 | + }); |
| 206 | + } |
| 207 | + setupElectronBootVars(); |
| 208 | + } |
146 | 209 | </script> |
147 | 210 |
|
148 | 211 | <!-- Import the phoenix browser virtual file system --> |
|
211 | 274 | isDeskTop: !_mobileAndTabletCheck() && !_mobileCheck(), |
212 | 275 | isChromeOS: /CrOS/.test(navigator.userAgent), |
213 | 276 | isTauri: !!window.__TAURI__, |
| 277 | + isElectron: !!window.__ELECTRON__, |
214 | 278 | mobile: { |
215 | 279 | isAndroid: (navigator.userAgent.match(/Android/i) !== null), |
216 | 280 | isIos: (navigator.userAgent.match(/iPhone|iPad|iPod/i) !== null), |
|
290 | 354 | 'https://create.phcode.dev': true |
291 | 355 | } |
292 | 356 | }; |
293 | | - window.Phoenix.isNativeApp = window.Phoenix.browser.isTauri; |
| 357 | + window.Phoenix.isNativeApp = window.__IS_NATIVE_SHELL__; |
294 | 358 | window.Phoenix.TRUSTED_ORIGINS[location.origin] = true; |
295 | 359 | Phoenix.isSupportedBrowser = Phoenix.isNativeApp || |
296 | 360 | (Phoenix.browser.isDeskTop && ("serviceWorker" in navigator)); |
|
0 commit comments