Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Fixes background trigger (#925)
Browse files Browse the repository at this point in the history
* Updates SDK and uses new background trigger method
  • Loading branch information
andrewxhill authored Feb 10, 2019
1 parent 2961584 commit 485dbbb
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 43 deletions.
6 changes: 1 addition & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ install-android-tools: &install-android-tools
echo y | sdkmanager "platforms;android-27"
echo y | sdkmanager "build-tools;28.0.3"
echo y | sdkmanager "platforms;android-28"
jobs:
lint:
working_directory: ~/textile-mobile
Expand Down Expand Up @@ -41,12 +40,10 @@ jobs:
name: tsc
command: |
yarn tsc
- run:
name: lint
command: |
yarn lint
# cache our yarn cache
- save_cache:
key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}
Expand Down Expand Up @@ -293,7 +290,6 @@ jobs:
name: release apk
command: |
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} android/app/build/outputs/apk/release/*.apk
ios:
macos:
xcode: "10.0.0"
Expand Down Expand Up @@ -607,4 +603,4 @@ workflows:
tags:
only: /^android_[0-9.]+_[0-9]+/
branches:
ignore: /.*/
ignore: /.*/
2 changes: 1 addition & 1 deletion App/Redux/TextileEventsRedux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const actions = {
),
newErrorMessage: createAction(
'@bridge/NEW_ERROR_MESSAGE',
(resolve) => (error: string) => resolve({ error })
(resolve) => (type: string, message: string) => resolve({ type, message })
),
startNodeFinished: createAction(
'@bridge/startNodeFinished',
Expand Down
2 changes: 1 addition & 1 deletion App/SB/views/ReduxState/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ReduxState extends React.PureComponent {
data={this.props.textLines}
renderItem={this.renderRow}
numColumns={1}
keyExtractor={(item, index) => index}
keyExtractor={(item, index) => String(index)}
/>
</View>
)
Expand Down
4 changes: 2 additions & 2 deletions App/Sagas/Account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {

export default function * accountSaga () {
yield all([
call(onNodeStarted),
call(refreshProfile),
call(refreshPeerId),
call(setUsername),
call(setAvatar),
call(getCafeSessions),
call(refreshCafeSessions),
call(onNodeStarted)
call(refreshCafeSessions)
])
}
36 changes: 22 additions & 14 deletions App/Sagas/TextileEventsSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import TextileEventsActions from '../Redux/TextileEventsRedux'
import RNPushNotification from 'react-native-push-notification'
import { RootAction } from '../Redux/Types'
import Textile, {
ContactInfo
ContactInfo,
BackgroundTask
} from '@textile/react-native-sdk'
import { logNewEvent } from './DeviceLogs'
import { pendingInvitesTask, cameraRollThreadCreateTask } from './ThreadsSagas'
import { RootState } from '../Redux/Types'
import { AsyncStorage } from 'react-native'

export function * startSagas () {
yield all([
Expand All @@ -30,6 +32,10 @@ export function * startSagas () {
])
}

export function * runBackgroundUpdate () {
yield call(BackgroundTask)
}

export function * refreshMessages () {
while (true) {
try {
Expand All @@ -41,7 +47,7 @@ export function * refreshMessages () {
yield call(Textile.checkCafeMessages)
yield call(logNewEvent, 'refreshMessages', action.type)
} catch (error) {
// handle errors
yield call(logNewEvent, 'refreshMessages', error.message, true)
}
}
}
Expand All @@ -60,6 +66,7 @@ export function * updateProfile () {

yield call(logNewEvent, 'refreshMessages', action.type)
} catch (error) {
yield call(logNewEvent, 'updateProfile', error.message, true)
yield put(AccountActions.profileError(error))
}
}
Expand All @@ -78,7 +85,7 @@ export function * ignoreFileRequest () {

yield call(logNewEvent, 'ignoreFile', action.type)
} catch (error) {
// handle error
yield call(logNewEvent, 'ignoreFileRequest', error.message, true)
}
}
}
Expand All @@ -95,9 +102,10 @@ export function * appStateChange () {
if (yield select(PreferencesSelectors.verboseUi)) {
yield call(displayNotification, 'App State Change: ' + action.payload.newState)
}

yield call(logNewEvent, 'State Change', action.payload.newState)
} catch (error) {
// handle errors
yield call(logNewEvent, 'appStateChange', error.message, true)
}
}
}
Expand All @@ -109,6 +117,7 @@ export function * nodeOnline () {
yield take((action: RootAction) =>
action.type === getType(TextileEventsActions.nodeOnline)
)
yield call(logNewEvent, 'Node is:', 'online')

// Check for new photos on every online event
yield put(StorageActions.refreshLocalImagesRequest())
Expand All @@ -120,10 +129,8 @@ export function * nodeOnline () {

// Only run this after everything else in the node is running
yield put(MigrationActions.requestRunRecurringMigrationTasks())

yield call(logNewEvent, 'Node is:', 'online')
} catch (error) {
// handle errors
yield call(logNewEvent, 'nodeOnline', error.message, true)
}
}
}
Expand All @@ -142,7 +149,7 @@ export function * startNodeFinished () {
yield call(cameraRollThreadCreateTask)

} catch (error) {
// handle errors
yield call(logNewEvent, 'startNodeFinished', error.message, true)
}
}
}
Expand All @@ -160,7 +167,7 @@ export function * stopNodeAfterDelayStarting () {
yield call(displayNotification, 'Running the node for 20 sec. in the background')
}
} catch (error) {
// handle errors
yield call(logNewEvent, 'stopNodeAfterDelayStarting', error.message, true)
}
}
}
Expand All @@ -183,7 +190,7 @@ export function * stopNodeAfterDelayCancelled () {
yield put(StorageActions.refreshLocalImagesRequest())

} catch (error) {
// handle errors
yield call(logNewEvent, 'stopNodeAfterDelayCancelled', error.message, true)
}
}
}
Expand All @@ -200,7 +207,7 @@ export function * stopNodeAfterDelayFinishing () {
yield call(displayNotification, 'Stopping node')
}
} catch (error) {
// handle errors
yield call(logNewEvent, 'stopNodeAfterDelayFinishing', error.message, true)
}
}
}
Expand All @@ -217,7 +224,7 @@ export function * stopNodeAfterDelayComplete () {
yield call(displayNotification, 'Node stopped')
}
} catch (error) {
// handle errors
yield call(logNewEvent, 'stopNodeAfterDelayComplete', error.message, true)
}
}
}
Expand All @@ -231,10 +238,11 @@ export function * newError () {
)

if (yield select(PreferencesSelectors.verboseUi)) {
yield call(displayNotification, action.payload.error, 'Error')
yield call(displayNotification, action.payload.type, action.payload.message)
}
yield call(logNewEvent, action.payload.type, action.payload.message, true)
} catch (error) {
// handle errors
yield call(logNewEvent, 'newError error', error.message, true)
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions App/Sagas/ThreadsSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ export function * pendingInvitesTask () {

export function * cameraRollThreadCreateTask () {
// Update our camera roll
const threadsResult: ReadonlyArray<ThreadInfo> = yield call(Textile.threads)
const cameraRollThreadName = 'Camera Roll'
const cameraRollThreadKey = Config.RN_TEXTILE_CAMERA_ROLL_THREAD_KEY
const cameraRollThread = threadsResult.find((thread) => thread.key === cameraRollThreadKey)
if (!cameraRollThread) {
try {
const threadsResult: ReadonlyArray<ThreadInfo> = yield call(Textile.threads)
const cameraRollThreadName = 'Camera Roll'
const cameraRollThreadKey = Config.RN_TEXTILE_CAMERA_ROLL_THREAD_KEY
yield call(Textile.addThread, cameraRollThreadKey, cameraRollThreadName, false)
} catch (error) {
// TODO: the camera sync relies on this tread existing, so if any other besides UNIQUE constraint, we should try again
}
}

Expand Down
16 changes: 7 additions & 9 deletions App/Sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ import {
} from './TextileSagas'

import {
runBackgroundUpdate,
startSagas
} from './TextileEventsSagas'

/*--- NEW SDK ---*/
import Textile from '@textile/react-native-sdk'

/* ------------- Connect Types To Sagas ------------- */

export default function * root (dispatch: Dispatch) {
Expand Down Expand Up @@ -158,6 +156,11 @@ export default function * root (dispatch: Dispatch) {
// takeEvery(getType(UploadingImagesActions.imageUploadComplete), removePayloadFile),
// takeEvery(getType(UploadingImagesActions.imageUploadError), handleUploadError),

/* ------------- SDK ------------- */
takeLatest(getType(TriggersActions.backgroundFetch), runBackgroundUpdate),
takeLatest(getType(TriggersActions.locationUpdate), runBackgroundUpdate),
/* ------------- End SDK ------------- */

takeEvery(getType(ThreadsActions.threadQRCodeRequest), displayThreadQRCode),
takeEvery(getType(ThreadsActions.addExternalInviteRequest), addExternalInvite),
takeEvery(getType(ThreadsActions.addExternalInviteSuccess), presentShareInterface),
Expand Down Expand Up @@ -189,11 +192,6 @@ export default function * root (dispatch: Dispatch) {

// DeepLinks
takeEvery(getType(UIActions.routeDeepLinkRequest), routeDeepLink),
takeEvery(getType(PreferencesActions.onboardingSuccess), inviteAfterOnboard),

/* ------------- SDK ------------- */
takeLatest(getType(TriggersActions.backgroundFetch), Textile.backgroundFetch),
takeLatest(getType(TriggersActions.locationUpdate), Textile.locationUpdate)
/* ------------- End SDK ------------- */
takeEvery(getType(PreferencesActions.onboardingSuccess), inviteAfterOnboard)
])
}
4 changes: 2 additions & 2 deletions App/Services/EventHandlers/TextileNodeEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export default class TextileNodeEventHandler {
DeviceEventEmitter.addListener('@textile/updateProfile', () => {
this.store.dispatch(TextileEventsActions.updateProfile())
})
DeviceEventEmitter.addListener('@textile/newErrorMessage', (payload) => {
this.store.dispatch(TextileEventsActions.newErrorMessage(payload.error))
DeviceEventEmitter.addListener('@textile/error', (payload) => {
this.store.dispatch(TextileEventsActions.newErrorMessage(payload.type, payload.message))
})
// Account actions
DeviceEventEmitter.addListener('@textile/setRecoveryPhrase', (payload) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@textile/react-native-icon": "^1.0.0",
"@textile/react-native-protobufs": "^1.1.0",
"@textile/react-native-screen-control": "1.0.12",
"@textile/react-native-sdk": "1.1.0-rc9",
"@textile/react-native-sdk": "1.1.0-rc10",
"@textile/redux-saga-wait-for": "1.0.1",
"moment": "^2.22.2",
"prop-types": "^15.6.2",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,9 @@
version "1.0.12"
resolved "https://registry.yarnpkg.com/@textile/react-native-screen-control/-/react-native-screen-control-1.0.12.tgz#1be41a4eaa9648fa4766e2489a6c2764d95985e1"

"@textile/[email protected]rc9":
version "1.1.0-rc9"
resolved "https://registry.yarnpkg.com/@textile/react-native-sdk/-/react-native-sdk-1.1.0-rc9.tgz#255a5a89ad2b7e0ff7b51e667b48c6e982526e07"
"@textile/[email protected]rc10":
version "1.1.0-rc10"
resolved "https://registry.yarnpkg.com/@textile/react-native-sdk/-/react-native-sdk-1.1.0-rc10.tgz#9c3cbc6aa66e12fbd7ec51cc0b0b6658c58fb6be"
dependencies:
"@textile/go-mobile" "1.0.0-rc31"
"@textile/react-native-protobufs" "1.1.0"
Expand Down

0 comments on commit 485dbbb

Please sign in to comment.