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

cleanup useSyncTask #283

Merged
merged 10 commits into from
Jun 17, 2023
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
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"cordova-plugin-email-composer": "^0.10.1",
"cordova-plugin-ionic": "5.5.3",
"cordova-sqlite-storage": "^6.1.0",
"eventemitter2": "^6.4.9",
"ionicons": "^7.1.0",
"jwt-decode": "^3.1.2",
"pinia": "^2.0.33",
Expand Down
1 change: 1 addition & 0 deletions src/app/decks/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './composables/useLibraryCache'
export * from './composables/useIndexedList'
export * from './tasks/useEnterFullscreenMode'

export { default as VerseTextLines } from './components/VerseTextLines.vue'
export { default as StackedFlipCardsDeck } from './components/StackedFlipCardsDeck.vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { watch } from 'vue'
import { storeToRefs } from 'pinia'
import { StatusBar } from '@capacitor/status-bar'
import { Capacitor } from '@capacitor/core'
import { useScreenOrientation , useAppStateStore } from '@/app/shared'
import { useSettingsStore } from '@/app/settings'
import { useScreenOrientation } from '../composables/useScreenOrientation'
import { useAppStateStore } from '../stores/appStateStore'


/**
* Enter fullscreen mode when in landscape mode and hide controls is enabled.
*/
export function runEnterFullscreenMode() {
export function useEnterFullscreenMode() {
/* -------------------------------------------------------------------------- */
/* Dependencies */
/* -------------------------------------------------------------------------- */
Expand All @@ -27,13 +27,15 @@ export function runEnterFullscreenMode() {


/* -------------------------------------------------------------------------- */
/* Init */
/* Actions */
/* -------------------------------------------------------------------------- */

watch(
[screenOrientation.isPortrait, routeName],
onChanged
)
async function run() {
watch(
[screenOrientation.isPortrait, routeName],
onChanged
)
}


/* -------------------------------------------------------------------------- */
Expand All @@ -45,5 +47,16 @@ export function runEnterFullscreenMode() {
const isFullscreenEligible = fullscrenEligibleRoutes.includes(routeName.value)
const hideControls = hideControlsInLandscapeMode.value
appStateStore.fullscreen = isLandscape && isFullscreenEligible && hideControls

if (Capacitor.getPlatform() !== 'web') {
if (appStateStore.fullscreen) { await StatusBar.hide() } else { await StatusBar.show() }
}
}


/* -------------------------------------------------------------------------- */
/* Interface */
/* -------------------------------------------------------------------------- */

return { run }
}
5 changes: 1 addition & 4 deletions src/app/settings/pages/AccountPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import {
import { mail, logoApple, logoGoogle } from 'ionicons/icons'
import { computed, inject } from 'vue'
import { Capacitor } from '@capacitor/core'
import { go, useAuthentication, useEmitter, useSync , BackgroundTasks } from '@/app/shared'
import { go, useAuthentication, useSync , BackgroundTasks } from '@/app/shared'
import { useSettingsStore } from '@/app/settings'
import { CouchDB } from '@/services/persistence'

Expand All @@ -100,7 +100,6 @@ import { CouchDB } from '@/services/persistence'
/* -------------------------------------------------------------------------- */

const userDataDb = inject('userData') as CouchDB
const emitter = useEmitter()
const settings = useSettingsStore()
const auth = useAuthentication()
const router = useIonRouter()
Expand All @@ -121,7 +120,6 @@ const isAuthenticated = computed(() => !!settings.authToken)

async function onSync() {
await syncTask.run({ force: true })
emitter.emit('syncCompleted')
}

async function onSignIn(strategy: string) {
Expand Down Expand Up @@ -152,6 +150,5 @@ async function onLogOut() {
settings.syncCollectionId = ''
settings.syncAt = 0
await userDataDb.destroy()
emitter.emit('syncCompleted')
}
</script>
4 changes: 1 addition & 3 deletions src/app/settings/pages/EmailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<script setup lang="ts">
import { IonContent, IonHeader, IonList, IonItem, IonToolbar, IonButtons, IonButton, IonTitle, IonInput, IonPage, IonBackButton, IonFooter, useIonRouter, alertController } from '@ionic/vue'
import { ref, watch } from 'vue'
import { useAuthentication, useEmitter } from '@/app/shared'
import { useAuthentication } from '@/app/shared'


/* -------------------------------------------------------------------------- */
Expand All @@ -96,7 +96,6 @@ const props = defineProps<{

const router = useIonRouter()
const auth = useAuthentication()
const emitter = useEmitter()

/* -------------------------------------------------------------------------- */
/* State */
Expand Down Expand Up @@ -149,7 +148,6 @@ async function onSignIn() {
email: email.value,
code: code.value,
})
emitter.emit('signedIn')
state.value = LoginState.SignedIn
navigateNext(props.nextUrl, props.navigationType)
} catch (e) {
Expand Down
37 changes: 0 additions & 37 deletions src/app/shared/composables/useEmitter.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/shared/composables/useSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useEnv } from './useEnv'
import { useAuthentication } from './useAuthentication'
import { useApplication } from './useApp'
import { useLogger } from './useLogger'
import { useEmitter } from './useEmitter'

/* -------------------------------------------------------------------------- */
/* Interface */
Expand Down Expand Up @@ -34,7 +33,6 @@ export function useSync() {
const auth = useAuthentication()
const env = useEnv()
const log = useLogger('sync')
const emitter = useEmitter()


/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -72,7 +70,6 @@ export function useSync() {
currentTime: currentTime
})
settings.syncAt = currentTime
emitter.emit('syncCompleted')
} catch (e) {
log.error('Syncing failed...', e)
throw new Error('Syncing failed: ' + JSON.stringify(e))
Expand Down
9 changes: 3 additions & 6 deletions src/app/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ export * from './composables/useApp'
export * from './composables/useDeviceStorage'
export * from './composables/useAuthentication'
export * from './composables/useSync'
export * from './composables/useEmitter'
export * from './composables/useTestId'
export * from './composables/useClearCache'
export * from './composables/useAppVersion'
export * from './composables/useArrayShuffler'
export * from './composables/useScreenOrientation'

// tasks:
export * from './tasks/runSyncTask'
export * from './tasks/runEnterFullscreenMode'
export * from './tasks/runHideStatusBar'
export * from './tasks/runScheduleNotifications'
export * from './tasks/runUpdateAppBadge'
export * from './tasks/useSyncTask'
export * from './tasks/useScheduleNotifications'
export * from './tasks/useUpdateAppBadge'
export * from './tasks/useResetMemorizationTime'
export * from './tasks/useAppStatePersistenceTask'

Expand Down
3 changes: 1 addition & 2 deletions src/app/shared/stores/appStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { ref } from 'vue'
* Global app state.
*/
export const useAppStateStore = defineStore('appState', () => {
const isActive = ref(true)
// const appStateChangedAt = ref(0)
const isActive = ref(false)

/**
* If true, the app is in fullscreen mode, otherwise not. In fullscreen mode,
Expand Down
49 changes: 0 additions & 49 deletions src/app/shared/tasks/runSyncTask.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/app/shared/tasks/useAppStatePersistenceTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function useAppStatePersistenceTask() {
/* -------------------------------------------------------------------------- */

async function onAppStateChanged() {
if (isActive.value) { return }
logger.debug('Saving app state')
for (const key of settingsKeys) {
// @ts-ignore
Expand Down
34 changes: 28 additions & 6 deletions src/app/shared/tasks/useResetMemorizationTime.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
import { useAppStateStore } from '@/app/shared'
import { storeToRefs } from 'pinia'
import { watch } from 'vue'
import { useAppStateStore, useApplication } from '@/app/shared'


export function useResetMemorizationTime() {
/* -------------------------------------------------------------------------- */
/* Dependencies */
/* -------------------------------------------------------------------------- */

const appState = useAppStateStore()
const app = useApplication()
const appStateStore = useAppStateStore()


/* -------------------------------------------------------------------------- */
/* State */
/* -------------------------------------------------------------------------- */

const { isActive } = storeToRefs(appStateStore)


/* -------------------------------------------------------------------------- */
/* Actions */
/* -------------------------------------------------------------------------- */

async function run() {
const lastResetAt = appState.memorizationTimeResetAt
const now = new Date()
watch([
isActive, app.now
], reset)
reset()
}


/* -------------------------------------------------------------------------- */
/* Helpers */
/* -------------------------------------------------------------------------- */

async function reset() {
const lastResetAt = appStateStore.memorizationTimeResetAt
const now = app.now.value
const today = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`

if (lastResetAt !== today) {
appState.memorizationTimeSpend = 0
appState.memorizationTimeResetAt = today
appStateStore.memorizationTimeSpend = 0
appStateStore.memorizationTimeResetAt = today
}
}

Expand Down
Loading