UNPKG

@plasosdk/plaso-electron-sdk

Version:

伯索课堂Electron SDK

110 lines (100 loc) 3.27 kB
function versionComp(newVersion, oldVersion) { const newVersionList = (newVersion || '0').split('.'); const oldVersionList = (oldVersion || '0').split('.'); const length = newVersionList.length > oldVersionList.length ? newVersionList.length : oldVersionList.length; for (let i = 0; i < length; i++) { const newVersionValue = newVersionList[i] == undefined ? 0 : parseInt(newVersionList[i]); const oldVersionValue = oldVersionList[i] == undefined ? 0 : parseInt(oldVersionList[i]); const res = newVersionValue - oldVersionValue; if (res !== 0) { return res; } } return 0; } function getElectronRemote() { let _remote; try { _remote = window.require('electron').remote; if (!_remote) { _remote = window.require('@electron/remote'); } } catch (e) { console.error(e); } return _remote; } function parseUrlParams(url) { const params = {}; const queryString = url.indexOf('?') > -1 ? url.split('?')[1] : url; if (!queryString) return params; queryString.split('&').forEach((pair) => { const [key, value] = pair.split('='); let decodedValue = decodeURIComponent(value || ''); if (decodedValue === 'true' || decodedValue === 'false') { decodedValue = decodedValue === 'true'; } else if ( typeof decodedValue === 'string' && decodedValue.length > 0 && !isNaN(Number(decodedValue)) && Number(decodedValue) !== undefined && !decodedValue?.includes?.('.') ) { decodedValue = Number(decodedValue); } params[key] = decodedValue; }); return params; } function getEnvironment(url) { let host = (url ?? location.host) .replace('wwwr', 'www') .replace('devai', 'dev') .replace('testai', 'test') .replace('itestai', 'itest') .replace('bai', 'b') .replace('ai-cdn', 'www') .replace('ai.', 'www.') .toLocaleUpperCase(); const httpIndex = host.indexOf('://'); if (httpIndex > -1) { host = host.substring(httpIndex + 3); } const index = host.indexOf('.'); let environment = ''; //先根据url判断环境。这里single页面访问会用到 if (/^192\.|^127\.|localhost/.test(host)) { environment = 'local'; } else { environment = host.substring(0, index); } return environment?.toLowerCase(); } /** * 获取当前BrowserWindow实例 */ function getCurrentWindow() { const remote = getElectronRemote(); if (remote) { return remote.getCurrentWindow(); } } /** * 获取窗口所属的屏幕(当应用跨屏幕时,应该属于占用面积超过一半的那块屏幕) */ function getDisplayMatching() { const remote = getElectronRemote(); const currentWindow = getCurrentWindow(); if (remote && currentWindow) { const { screen } = remote; const currentWindowBounds = currentWindow.getBounds(); return screen.getDisplayMatching(currentWindowBounds); } } module.exports = { versionComp, getElectronRemote, parseUrlParams, getEnvironment, getDisplayMatching, };