Skip to content

Commit

Permalink
feat: add updater to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Nov 24, 2021
1 parent 197d8c3 commit 50f8508
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 27 deletions.
17 changes: 17 additions & 0 deletions android/.idea/deploymentTargetDropDown.xml

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

6 changes: 3 additions & 3 deletions android/app/src/main/assets/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-title" content="Mimesis" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<script type="module" crossorigin src="/assets/index.854554ee.js"></script>
<link rel="modulepreload" href="/assets/vendor.04f47e39.js">
<link rel="stylesheet" href="/assets/index.17452c15.css">
<script type="module" crossorigin src="/assets/index.a6ef221f.js"></script>
<link rel="modulepreload" href="/assets/vendor.3409d429.js">
<link rel="stylesheet" href="/assets/index.40ec6d51.css">
</head>

<body>
Expand Down
8 changes: 4 additions & 4 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2.0.11;
CURRENT_PROJECT_VERSION = 2.0.12;
DEVELOPMENT_TEAM = UVTJ336J2D;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 2.0.11;
MARKETING_VERSION = 2.0.12;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = ee.forgr.mimesis;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -389,12 +389,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2.0.11;
CURRENT_PROJECT_VERSION = 2.0.12;
DEVELOPMENT_TEAM = UVTJ336J2D;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 2.0.11;
MARKETING_VERSION = 2.0.12;
PRODUCT_BUNDLE_IDENTIFIER = ee.forgr.mimesis;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
Expand Down
28 changes: 15 additions & 13 deletions src/services/capacitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import { NativeAudio } from 'capacitor-native-audio'
import { SplashScreen } from '@capacitor/splash-screen'
import { StatusBar } from '@capacitor/status-bar'
import { isPlatform } from '@ionic/vue'
// import { App } from '@capacitor/app'
// import { CapacitorUpdater } from 'capacitor-updater'
import { App } from '@capacitor/app'
import { CapacitorUpdater } from 'capacitor-updater'
import { useMainStore } from '@/store/main'

export const initCapacitor = (): void => {
if (isPlatform('capacitor')) {
// Do the update when user lean app
// App.addListener('appStateChange', async (state) => {
// if (!state.isActive) {
// SplashScreen.show()
// const version = await CapacitorUpdater.download({
// url: 'https://github.com/Forgr-ee/Mimesis/releases/download/0.0.1/dist.zip',
// })
// await CapacitorUpdater.set(version)
// SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
// }
// })
const main = useMainStore()
App.addListener('appStateChange', async (state) => {
if (!state.isActive && main.lastVersion.folder === '') {
SplashScreen.show()
const newFolder = await CapacitorUpdater.download({
url: main.lastVersion.path,
})
main.lastVersion.folder = newFolder.version
await CapacitorUpdater.set({ version: main.lastVersion.folder })
SplashScreen.hide() // in case set fail, otherwise the new app will have to hide it
}
})
StatusBar.hide()

NativeAudio.preload({
Expand Down
18 changes: 18 additions & 0 deletions src/services/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export type GuessDb = {
[key: string]: Guess[]
}

export interface Config {
version: string
versionPath: string
}

export type Guess = {
title: string
cover?: string
Expand All @@ -68,6 +73,7 @@ type Usefirebase = {
getGuessesDb: (themes: Theme[], lang: string) => Promise<GuessDb>
getThemes: () => Promise<Theme[]>
getLangMessages: () => Promise<LangMessages>
getLastVersion: () => Promise<Config>
addGame: (
uid: string | undefined,
lang: string,
Expand Down Expand Up @@ -112,6 +118,17 @@ export const useFirebase = (): Usefirebase => {
}
return value
}
const getLastVersion = async (): Promise<Config> => {
try {
const config = (
await firebase.firestore().collection(`config`).doc('app').get()
).data() as Config
return config
} catch (err: any) {
console.error('getLastVersion', err)
throw new Error(err)
}
}
const getGuessesDb = async (
themes: Theme[],
lang: string
Expand Down Expand Up @@ -206,6 +223,7 @@ export const useFirebase = (): Usefirebase => {
return {
firebase,
getGuessesDb,
getLastVersion,
getThemes,
getLangMessages,
addGame,
Expand Down
31 changes: 28 additions & 3 deletions src/store/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CapacitorUpdater } from 'capacitor-updater'
import { randomSelect } from '../services/random'
import { defineStore } from 'pinia'

Expand All @@ -10,19 +11,30 @@ import {
} from '../services/firebase'
import { useGameStore } from './game'

const { getLangMessages, getThemes, getGuessesDb } = useFirebase()
const { getLangMessages, getThemes, getGuessesDb, getLastVersion } =
useFirebase()

const filterListByTitle = (list: Guess[], past: string[]) => {
const filtered = list.filter((n) => !past.includes(n.title))
return filtered
}
interface Version {
version: string
path: string
folder: string
}

export const useMainStore = defineStore('main', {
// other options...
state: () => ({
error: false,
loading: false,
version: '',
lastVersion: {
version: '',
path: '',
folder: '',
} as Version,
versions: [] as Version[],
lastUpdate: '',
initialized: false,
currentPath: '/home',
Expand Down Expand Up @@ -66,7 +78,11 @@ export const useMainStore = defineStore('main', {
return
this.loading = true
try {
await Promise.all([this.initLangMessages(), this.initThemes()])
await Promise.all([
this.initLangMessages(),
this.initThemes(),
this.getLastVersion(),
])
await this.initGuessTheme()
this.initialized = true
} catch (err: any) {
Expand All @@ -76,6 +92,15 @@ export const useMainStore = defineStore('main', {
this.lastUpdate = new Date().toISOString()
this.loading = false
},
async getLastVersion() {
const newVersion = await getLastVersion()
if (newVersion.version !== this.lastVersion.version) {
this.lastVersion.version = newVersion.version
this.lastVersion.path = newVersion.versionPath
this.lastVersion.folder = ''
this.versions.push(this.lastVersion)
}
},
async initGuessTheme() {
this.guessDb = await getGuessesDb(this.themes, this.lang)
},
Expand Down
5 changes: 1 addition & 4 deletions src/views/Game.vue
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,7 @@
const setupCanvas = () => {
const options = {
useWorker: true,
resize: true,
}
if (isPlatform('android') && isPlatform('capacitor')) {
options.resize = false
resize: !isPlatform('android'),
}
confetti = createConfetti(null as unknown as HTMLCanvasElement, options)
}
Expand Down

0 comments on commit 50f8508

Please sign in to comment.