Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

补充getLaunchOptionsSync #1717

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/api-proxy/src/platform/api/lifecycle/index.ali.js

This file was deleted.

7 changes: 0 additions & 7 deletions packages/api-proxy/src/platform/api/lifecycle/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions packages/api-proxy/src/platform/api/lifecycle/index.web.js

This file was deleted.

8 changes: 7 additions & 1 deletion packages/api-proxy/src/platform/api/system/index.ali.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 40,15 @@ const getDeviceInfo = function () {

const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')

const getLaunchOptionsSync = ENV_OBJ.getLaunchOptionsSync || envError('getLaunchOptionsSync')

const getEnterOptionsSync = ENV_OBJ.getEnterOptionsSync || envError('getEnterOptionsSync')

export {
getSystemInfo,
getSystemInfoSync,
getDeviceInfo,
getWindowInfo
getWindowInfo,
getLaunchOptionsSync,
getEnterOptionsSync
}
8 changes: 7 additions & 1 deletion packages/api-proxy/src/platform/api/system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 8,15 @@ const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')

const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')

const getLaunchOptionsSync = ENV_OBJ.getLaunchOptionsSync || envError('getLaunchOptionsSync')

const getEnterOptionsSync = ENV_OBJ.getEnterOptionsSync || envError('getEnterOptionsSync')

export {
getSystemInfo,
getSystemInfoSync,
getDeviceInfo,
getWindowInfo
getWindowInfo,
getLaunchOptionsSync,
getEnterOptionsSync
}
93 changes: 77 additions & 16 deletions packages/api-proxy/src/platform/api/system/index.web.js
Original file line number Diff line number Diff line change
@@ -1,10 1,6 @@
import { envError, isBrowser, throwSSRWarning, successHandle } from '../../../common/js'
import { isBrowser, throwSSRWarning, successHandle } from '../../../common/js'

function getSystemInfoSync () {
if (!isBrowser) {
throwSSRWarning('getSystemInfoSync API is running in non browser environments')
return
}
const getDeviceInfo = function () {
const ua = navigator.userAgent.split('(')[1]?.split(')')[0] || ''
const phones = new Map([
['iPhone', /iPhone|iPad|iPod|iOS/i],
Expand Down Expand Up @@ -37,20 33,57 @@ function getSystemInfoSync () {
} else {
system = `Android ${ua.replace(/^.*Android ([\d.] );.*$/, '$1')}`
}

return {
brand: brand,
abi: null,
deviceAbi: null,
benchmarkLevel: null,
brand,
model: brand,
system,
platform: navigator.platform,
cpuType: null,
memorySize: null
}
}

const getWindowInfo = function () {
return {
pixelRatio: window.devicePixelRatio,
screenWidth: window.screen.width,
screenHeight: window.screen.height,
windowWidth: document.documentElement.clientWidth,
windowHeight: document.documentElement.clientHeight,
statusBarHeight: null,
safeArea: null,
screenTop: null
}
}

function getSystemInfoSync () {
if (!isBrowser) {
throwSSRWarning('getSystemInfoSync API is running in non browser environments')
return
}

const {
pixelRatio,
screenWidth,
screenHeight,
windowWidth,
windowHeight,
statusBarHeight,
safeArea
} = getWindowInfo()
const {
benchmarkLevel,
brand,
model,
system,
platform
} = getDeviceInfo()
const result = Object.assign({
language: navigator.language,
version: null,
system,
platform: navigator.platform,
fontSizeSetting: null,
SDKVersion: null,
benchmarkLevel: null,
Expand All @@ -64,9 97,23 @@ function getSystemInfoSync () {
notificationSoundAuthorized: null,
bluetoothEnabled: null,
locationEnabled: null,
wifiEnabled: null,
safeArea: null
}
wifiEnabled: null
}, {
pixelRatio,
screenWidth,
screenHeight,
windowWidth,
windowHeight,
statusBarHeight,
safeArea
}, {
benchmarkLevel,
brand,
model,
system,
platform
})
return result
}

function getSystemInfo (options = {}) {
Expand All @@ -79,13 126,27 @@ function getSystemInfo (options = {}) {
successHandle(res, options.success, options.complete)
}

const getDeviceInfo = envError('getDeviceInfo')
const getEnterOptionsSync = function () {
if (!isBrowser) {
throwSSRWarning('getEnterOptionsSync API is running in non browser environments')
return
}
return global.__mpxEnterOptions || {}
}

const getWindowInfo = envError('getWindowInfo')
const getLaunchOptionsSync = function () {
if (!isBrowser) {
throwSSRWarning('getLaunchOptionsSync API is running in non browser environments')
return
}
return global.__mpxEnterOptions || {}
}

export {
getSystemInfo,
getSystemInfoSync,
getDeviceInfo,
getWindowInfo
getWindowInfo,
getLaunchOptionsSync,
getEnterOptionsSync
}
19 changes: 18 additions & 1 deletion packages/api-proxy/src/platform/api/system/rnSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 75,26 @@ const getDeviceInfo = function () {
return deviceInfo
}

const getLaunchOptionsSync = function () {
const options = global.__mpxEnterOptions || {}
const { path, scene, query } = options
return {
path,
scene,
query
}
}

const getEnterOptionsSync = function () {
const result = getLaunchOptionsSync()
return result
}

export {
getSystemInfo,
getSystemInfoSync,
getDeviceInfo,
getWindowInfo
getWindowInfo,
getLaunchOptionsSync,
getEnterOptionsSync
}
3 changes: 0 additions & 3 deletions packages/api-proxy/src/platform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 105,6 @@ export * from './api/video'
// onWindowResize, offWindowResize
export * from './api/window'

// getEnterOptionsSync
export * from './api/lifecycle'

// getLocation, openLocation, chooseLocation
export * from './api/location'

Expand Down
Loading