-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathcore.ts
More file actions
94 lines (78 loc) · 2.84 KB
/
core.ts
File metadata and controls
94 lines (78 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
import { emptyModule, error, log } from './utils';
import i18n from './i18n';
const {
version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const isTurboModuleEnabled =
// https://github.com/facebook/react-native/pull/48362
(global as any).__turboModuleProxy || (global as any).RN$Bridgeless;
export const PushyModule =
Platform.OS === 'web'
? emptyModule
: isTurboModuleEnabled
? require('./NativePushy').default
: NativeModules.Pushy;
export const UpdateModule = PushyModule;
if (!PushyModule) {
throw Error(
'Failed to load react-native-update native module, please try to recompile',
);
}
const PushyConstants = isTurboModuleEnabled
? PushyModule.getConstants()
: PushyModule;
export const downloadRootDir: string = PushyConstants.downloadRootDir;
export const packageVersion: string = PushyConstants.packageVersion;
export const currentVersion: string = PushyConstants.currentVersion;
export function setLocalHashInfo(hash: string, info: Record<string, any>) {
PushyModule.setLocalHashInfo(hash, JSON.stringify(info));
}
const currentVersionInfoString: string = PushyConstants.currentVersionInfo;
let _currentVersionInfo: Record<string, any> = {};
let isDebugChannel = false;
if (currentVersionInfoString) {
try {
_currentVersionInfo = JSON.parse(currentVersionInfoString);
if (_currentVersionInfo.debugChannel) {
isDebugChannel = true;
delete _currentVersionInfo.debugChannel;
setLocalHashInfo(currentVersion, _currentVersionInfo);
}
} catch (err) {
error(
i18n.t('error_parse_version_info', { info: currentVersionInfoString }),
);
}
}
export const currentVersionInfo = _currentVersionInfo;
export const isFirstTime: boolean = PushyConstants.isFirstTime;
export const isFirstTimeDebug: boolean = isFirstTime && isDebugChannel;
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
export const isRolledBack: boolean = !!rolledBackVersion;
export const buildTime: string = PushyConstants.buildTime;
let uuid = PushyConstants.uuid;
async function getLocalHashInfo(hash: string) {
return JSON.parse(await PushyModule.getLocalHashInfo(hash));
}
// @deprecated use currentVersionInfo instead
export async function getCurrentVersionInfo(): Promise<{
name?: string;
description?: string;
metaInfo?: string;
}> {
return currentVersion ? (await getLocalHashInfo(currentVersion)) || {} : {};
}
export const pushyNativeEventEmitter = new NativeEventEmitter(PushyModule);
if (!uuid) {
uuid = require('nanoid/non-secure').nanoid();
PushyModule.setUuid(uuid);
}
log('uuid: ' + uuid);
export const cInfo = {
rnu: require('../package.json').version,
rn: RNVersion,
os: Platform.OS + ' ' + Platform.Version,
uuid,
};