-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15593 from handsomeliuyang/main
oschannel实现优化,支持业务代态动态选择
- Loading branch information
Showing
17 changed files
with
341 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/taro-platform-harmony-hybrid/src/api/apis/base/getAppAuthorizeSetting/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Taro from '@tarojs/api' | ||
|
||
import { getAppAuthorizeSetting as nativeGetAppAuthorizeSetting } from './native' | ||
import { getAppAuthorizeSetting as osChannelGetAppAuthorizeSetting } from './oschannel' | ||
|
||
export const getAppAuthorizeSetting: typeof Taro.getAppAuthorizeSetting = (useNativeImpl: boolean = false) => { | ||
return useNativeImpl ? nativeGetAppAuthorizeSetting() : osChannelGetAppAuthorizeSetting() | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/taro-platform-harmony-hybrid/src/api/apis/base/getAppAuthorizeSetting/native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Taro from '@tarojs/api' | ||
|
||
import native from '../../NativeApi' | ||
|
||
/** | ||
* 获取APP授权设置 | ||
* | ||
* @canUse getAppAuthorizeSetting | ||
* @__return | ||
* [albumAuthorized, bluetoothAuthorized, cameraAuthorized, locationAuthorized, locationReducedAccuracy,\ | ||
* microphoneAuthorized, notificationAuthorized, phoneCalendarAuthorized] | ||
*/ | ||
export const getAppAuthorizeSetting: typeof Taro.getAppAuthorizeSetting = () => { | ||
const info = native.getAppAuthorizeSetting() | ||
// @ts-ignore | ||
const appAuthorizeSetting: Taro.getAppAuthorizeSetting.Result = { | ||
/** 允许微信使用相册的开关(仅 iOS 有效) */ | ||
albumAuthorized: info.albumAuthorized, | ||
/** 允许微信使用蓝牙的开关(仅 iOS 有效) */ | ||
bluetoothAuthorized: info.bluetoothAuthorized, | ||
/** 允许微信使用摄像头的开关 */ | ||
cameraAuthorized: info.cameraAuthorized, | ||
/** 允许微信使用定位的开关 */ | ||
locationAuthorized: info.locationAuthorized, | ||
/** 定位准确度。true 表示模糊定位,false 表示精确定位(仅 iOS 有效) */ | ||
locationReducedAccuracy: info.locationAccuracy === 'reduced', | ||
/** 允许微信使用麦克风的开关 */ | ||
microphoneAuthorized: info.microphoneAuthorized, | ||
/** 允许微信通知的开关 */ | ||
notificationAuthorized: info.notificationAuthorized, | ||
/** 允许微信读写日历的开关 */ | ||
phoneCalendarAuthorized: info.phoneCalendarAuthorized, | ||
} | ||
return appAuthorizeSetting | ||
} |
94 changes: 94 additions & 0 deletions
94
packages/taro-platform-harmony-hybrid/src/api/apis/base/getAppAuthorizeSetting/oschannel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import Taro from '@tarojs/api' | ||
|
||
|
||
let abilityAccessCtrl | ||
|
||
try { | ||
// @ts-ignore | ||
abilityAccessCtrl = requireNapi('abilityAccessCtrl') | ||
} catch (error) { | ||
} | ||
|
||
// @ts-ignore | ||
export const getAppAuthorizeSetting: typeof Taro.getAppAuthorizeSetting = () => { | ||
const permissionsList = { | ||
album: 'ohos.permission.WRITE_IMAGEVIDEO', | ||
bluetooth: 'ohos.permission.USE_BLUETOOTH', | ||
camera: 'ohos.permission.CAMERA', | ||
location: 'ohos.permission.LOCATION', | ||
locationAccuracy: 'ohos.permission.APPROXIMATELY_LOCATION', | ||
microphone: 'ohos.permission.MICROPHONE', | ||
notification: 'ohos.permission.NOTIFICATION_CONTROLLER', | ||
phoneCalendar: 'ohos.permission.READ_CALENDAR', | ||
} | ||
const atManager = abilityAccessCtrl.createAtManager() | ||
// @ts-ignore | ||
const tokenID = bundleInfoForSelf.appInfo.accessTokenId | ||
const grantStatus = (flag) => { | ||
if (flag === -1) { | ||
return 'denied' | ||
} else if (flag === 0) { | ||
return 'authorized' | ||
} | ||
return 'config error' | ||
} | ||
let albumAuthorized = 'not determined' | ||
try { | ||
albumAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.album) | ||
albumAuthorized = grantStatus(albumAuthorized) | ||
} catch (e) { | ||
} | ||
let bluetoothAuthorized = 'not determined' | ||
try { | ||
bluetoothAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.bluetooth) | ||
bluetoothAuthorized = grantStatus(bluetoothAuthorized) | ||
} catch (e) { | ||
} | ||
let cameraAuthorized = 'not determined' | ||
try { | ||
cameraAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.camera) | ||
cameraAuthorized = grantStatus(cameraAuthorized) | ||
} catch (e) { | ||
} | ||
let locationAuthorized = 'not determined' | ||
try { | ||
locationAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.location) | ||
locationAuthorized = grantStatus(locationAuthorized) | ||
} catch (e) { | ||
} | ||
let locationAccuracy = 'not determined' | ||
try { | ||
locationAccuracy = | ||
atManager.checkAccessTokenSync(tokenID, permissionsList.locationAccuracy) === 0 ? 'full' : 'reduced' | ||
} catch (e) { | ||
} | ||
let microphoneAuthorized = 'not determined' | ||
try { | ||
microphoneAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.microphone) | ||
microphoneAuthorized = grantStatus(microphoneAuthorized) | ||
} catch (e) { | ||
} | ||
let notificationAuthorized = 'not determined' | ||
try { | ||
notificationAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.notification) | ||
notificationAuthorized = grantStatus(notificationAuthorized) | ||
} catch (e) { | ||
} | ||
let phoneCalendarAuthorized = 'not determined' | ||
try { | ||
phoneCalendarAuthorized = atManager.checkAccessTokenSync(tokenID, permissionsList.phoneCalendar) | ||
phoneCalendarAuthorized = grantStatus(phoneCalendarAuthorized) | ||
} catch (e) { | ||
} | ||
const result = { | ||
albumAuthorized, | ||
bluetoothAuthorized, | ||
cameraAuthorized, | ||
locationAuthorized, | ||
locationAccuracy, | ||
microphoneAuthorized, | ||
notificationAuthorized, | ||
phoneCalendarAuthorized, | ||
} | ||
return result | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/taro-platform-harmony-hybrid/src/api/apis/base/getSystemSetting/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Taro from '@tarojs/api' | ||
|
||
import { getSystemSetting as nativeGetSystemSetting } from './native' | ||
import { getSystemSetting as osChannelGetSystemSetting } from './oschannel' | ||
|
||
export const getSystemSetting: typeof Taro.getSystemSetting = (useNativeImpl: boolean = false) => { | ||
return useNativeImpl ? nativeGetSystemSetting() : osChannelGetSystemSetting() | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/taro-platform-harmony-hybrid/src/api/apis/base/getSystemSetting/native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Taro from '@tarojs/api' | ||
|
||
import native from '../../NativeApi' | ||
|
||
|
||
const lastSystemSettingResult: Taro.getSystemSetting.Result = {} | ||
let lastGetSystemSettingTime = 0 | ||
|
||
/** | ||
* 获取设备设置 | ||
* | ||
* @canUse getSystemSetting | ||
* @__return [bluetoothEnabled, locationEnabled, wifiEnabled, deviceOrientation[portrait, landscape]] | ||
*/ | ||
export const getSystemSetting: typeof Taro.getSystemSetting = () => { | ||
const currentTime = Date.now() | ||
if (currentTime - lastGetSystemSettingTime < 500) { | ||
return lastSystemSettingResult | ||
} | ||
// @ts-ignore | ||
const info = native.getSystemSetting() | ||
lastSystemSettingResult.bluetoothEnabled = info.bluetoothEnabled | ||
lastSystemSettingResult.locationEnabled = info.locationEnabled | ||
lastSystemSettingResult.wifiEnabled = info.wifiEnabled | ||
lastSystemSettingResult.deviceOrientation = info.deviceOrientation | ||
lastGetSystemSettingTime = currentTime | ||
return lastSystemSettingResult | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/taro-platform-harmony-hybrid/src/api/apis/base/getSystemSetting/oschannel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Taro from '@tarojs/api' | ||
|
||
|
||
let bluetooth | ||
let geoLocationManager | ||
let wifiManager | ||
|
||
try { | ||
// @ts-ignore | ||
bluetooth = requireNapi('bluetooth') | ||
|
||
// @ts-ignore | ||
geoLocationManager = requireNapi('geoLocationManager') | ||
|
||
// @ts-ignore | ||
wifiManager = requireNapi('wifi') | ||
} catch (error) {} | ||
|
||
// @ts-ignore | ||
export const getSystemSetting: typeof Taro.getSystemSetting = () => { | ||
let bluetoothEnabled: number | boolean = false | ||
let locationEnabled = false | ||
let wifiEnabled = false | ||
let bluetoothError = '' | ||
let locationError = '' | ||
try { | ||
bluetoothEnabled = bluetooth.getState() | ||
bluetoothEnabled = bluetoothEnabled === 2 || bluetoothEnabled === 5 | ||
} catch (err) { | ||
console.error('errCode:' + err.code + ',errMessage:' + err.message) | ||
bluetoothError = err.message | ||
} | ||
try { | ||
locationEnabled = geoLocationManager.isLocationEnabled() | ||
} catch (err) { | ||
console.error('errCode:' + err.code + ',errMessage:' + err.message) | ||
locationError = err.message | ||
} | ||
try { | ||
wifiEnabled = wifiManager.isWifiActive() | ||
} catch (err) { | ||
console.error('errCode:' + err.code + ',errMessage:' + err.message) | ||
} | ||
// @ts-ignore | ||
const { rotation } = display.getDefaultDisplaySync() | ||
const deviceOrientation = rotation === 1 || rotation === 3 ? 'landscape' : 'portrait' | ||
return { | ||
bluetoothEnabled, | ||
bluetoothError, | ||
locationEnabled, | ||
locationError, | ||
wifiEnabled, | ||
deviceOrientation, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/taro-platform-harmony-hybrid/src/api/apis/device/keyBoard/hideKeyboard/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Taro from '@tarojs/taro' | ||
|
||
import { hideKeyboard as nativeHideKeyboard } from './native' | ||
import { hideKeyboard as osChannelHideKeyboard } from './oschannel' | ||
|
||
|
||
export const hideKeyboard: typeof Taro.hideKeyboard = (options, useNativeImpl: boolean = false) => { | ||
return useNativeImpl ? nativeHideKeyboard(options) : osChannelHideKeyboard(options) | ||
} |
Oops, something went wrong.