chore: upgrade mobile dependencies (#2578)
This commit is contained in:
@@ -13,6 +13,7 @@ import CustomAndroidWebView from './CustomAndroidWebView'
|
||||
import { MobileDevice, MobileDeviceEvent } from './Lib/MobileDevice'
|
||||
import { IsDev } from './Lib/Utils'
|
||||
import { ReceivedSharedItemsHandler } from './ReceivedSharedItemsHandler'
|
||||
import { ReviewService } from './ReviewService'
|
||||
|
||||
const LoggingEnabled = IsDev
|
||||
|
||||
@@ -37,6 +38,7 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
||||
() => new MobileDevice(stateService, androidBackHandlerService, colorSchemeService),
|
||||
[androidBackHandlerService, colorSchemeService, stateService],
|
||||
)
|
||||
const _reviewService = useRef(new ReviewService(device))
|
||||
|
||||
const [showAndroidWebviewUpdatePrompt, setShowAndroidWebviewUpdatePrompt] = useState(false)
|
||||
|
||||
|
||||
34
packages/mobile/src/ReviewService.ts
Normal file
34
packages/mobile/src/ReviewService.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { ApplicationEvent } from '@standardnotes/snjs'
|
||||
import { MobileDevice } from 'Lib/MobileDevice'
|
||||
import * as StoreReview from 'react-native-store-review'
|
||||
|
||||
const RUN_COUNTS_BEFORE_REVIEW = [18, 45, 105]
|
||||
|
||||
export class ReviewService {
|
||||
constructor(private device: MobileDevice) {
|
||||
this.device.addApplicationEventReceiver(this.onApplicationEvent.bind(this))
|
||||
}
|
||||
async onApplicationEvent(event: ApplicationEvent) {
|
||||
if (event !== ApplicationEvent.Launched) {
|
||||
return
|
||||
}
|
||||
const runCount = await this.getRunCount()
|
||||
void this.setRunCount(runCount + 1)
|
||||
if (RUN_COUNTS_BEFORE_REVIEW.includes(runCount)) {
|
||||
setTimeout(function () {
|
||||
try {
|
||||
StoreReview.requestReview()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
async getRunCount() {
|
||||
const value = await this.device.getJsonParsedRawStorageValue('runCount')
|
||||
return Number(value) || 0
|
||||
}
|
||||
async setRunCount(runCount: number) {
|
||||
return this.device.setRawStorageValue('runCount', runCount.toString())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user