Skip to content

Commit 50f8508

Browse files
committed
feat: add updater to codebase
1 parent 197d8c3 commit 50f8508

File tree

7 files changed

+86
-27
lines changed

7 files changed

+86
-27
lines changed

android/.idea/deploymentTargetDropDown.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/app/src/main/assets/public/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<meta name="apple-mobile-web-app-capable" content="yes" />
2020
<meta name="apple-mobile-web-app-title" content="Mimesis" />
2121
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
22-
<script type="module" crossorigin src="/assets/index.854554ee.js"></script>
23-
<link rel="modulepreload" href="/assets/vendor.04f47e39.js">
24-
<link rel="stylesheet" href="/assets/index.17452c15.css">
22+
<script type="module" crossorigin src="/assets/index.a6ef221f.js"></script>
23+
<link rel="modulepreload" href="/assets/vendor.3409d429.js">
24+
<link rel="stylesheet" href="/assets/index.40ec6d51.css">
2525
</head>
2626

2727
<body>

ios/App/App.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@
368368
buildSettings = {
369369
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
370370
CODE_SIGN_STYLE = Automatic;
371-
CURRENT_PROJECT_VERSION = 2.0.11;
371+
CURRENT_PROJECT_VERSION = 2.0.12;
372372
DEVELOPMENT_TEAM = UVTJ336J2D;
373373
INFOPLIST_FILE = App/Info.plist;
374374
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
375375
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
376-
MARKETING_VERSION = 2.0.11;
376+
MARKETING_VERSION = 2.0.12;
377377
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
378378
PRODUCT_BUNDLE_IDENTIFIER = ee.forgr.mimesis;
379379
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -389,12 +389,12 @@
389389
buildSettings = {
390390
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
391391
CODE_SIGN_STYLE = Automatic;
392-
CURRENT_PROJECT_VERSION = 2.0.11;
392+
CURRENT_PROJECT_VERSION = 2.0.12;
393393
DEVELOPMENT_TEAM = UVTJ336J2D;
394394
INFOPLIST_FILE = App/Info.plist;
395395
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
396396
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
397-
MARKETING_VERSION = 2.0.11;
397+
MARKETING_VERSION = 2.0.12;
398398
PRODUCT_BUNDLE_IDENTIFIER = ee.forgr.mimesis;
399399
PRODUCT_NAME = "$(TARGET_NAME)";
400400
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";

src/services/capacitor.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ import { NativeAudio } from 'capacitor-native-audio'
22
import { SplashScreen } from '@capacitor/splash-screen'
33
import { StatusBar } from '@capacitor/status-bar'
44
import { isPlatform } from '@ionic/vue'
5-
// import { App } from '@capacitor/app'
6-
// import { CapacitorUpdater } from 'capacitor-updater'
5+
import { App } from '@capacitor/app'
6+
import { CapacitorUpdater } from 'capacitor-updater'
7+
import { useMainStore } from '@/store/main'
78

89
export const initCapacitor = (): void => {
910
if (isPlatform('capacitor')) {
10-
// Do the update when user lean app
11-
// App.addListener('appStateChange', async (state) => {
12-
// if (!state.isActive) {
13-
// SplashScreen.show()
14-
// const version = await CapacitorUpdater.download({
15-
// url: 'https://github.com/Forgr-ee/Mimesis/releases/download/0.0.1/dist.zip',
16-
// })
17-
// await CapacitorUpdater.set(version)
18-
// SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
19-
// }
20-
// })
11+
const main = useMainStore()
12+
App.addListener('appStateChange', async (state) => {
13+
if (!state.isActive && main.lastVersion.folder === '') {
14+
SplashScreen.show()
15+
const newFolder = await CapacitorUpdater.download({
16+
url: main.lastVersion.path,
17+
})
18+
main.lastVersion.folder = newFolder.version
19+
await CapacitorUpdater.set({ version: main.lastVersion.folder })
20+
SplashScreen.hide() // in case set fail, otherwise the new app will have to hide it
21+
}
22+
})
2123
StatusBar.hide()
2224

2325
NativeAudio.preload({

src/services/firebase.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export type GuessDb = {
4343
[key: string]: Guess[]
4444
}
4545

46+
export interface Config {
47+
version: string
48+
versionPath: string
49+
}
50+
4651
export type Guess = {
4752
title: string
4853
cover?: string
@@ -68,6 +73,7 @@ type Usefirebase = {
6873
getGuessesDb: (themes: Theme[], lang: string) => Promise<GuessDb>
6974
getThemes: () => Promise<Theme[]>
7075
getLangMessages: () => Promise<LangMessages>
76+
getLastVersion: () => Promise<Config>
7177
addGame: (
7278
uid: string | undefined,
7379
lang: string,
@@ -112,6 +118,17 @@ export const useFirebase = (): Usefirebase => {
112118
}
113119
return value
114120
}
121+
const getLastVersion = async (): Promise<Config> => {
122+
try {
123+
const config = (
124+
await firebase.firestore().collection(`config`).doc('app').get()
125+
).data() as Config
126+
return config
127+
} catch (err: any) {
128+
console.error('getLastVersion', err)
129+
throw new Error(err)
130+
}
131+
}
115132
const getGuessesDb = async (
116133
themes: Theme[],
117134
lang: string
@@ -206,6 +223,7 @@ export const useFirebase = (): Usefirebase => {
206223
return {
207224
firebase,
208225
getGuessesDb,
226+
getLastVersion,
209227
getThemes,
210228
getLangMessages,
211229
addGame,

src/store/main.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CapacitorUpdater } from 'capacitor-updater'
12
import { randomSelect } from '../services/random'
23
import { defineStore } from 'pinia'
34

@@ -10,19 +11,30 @@ import {
1011
} from '../services/firebase'
1112
import { useGameStore } from './game'
1213

13-
const { getLangMessages, getThemes, getGuessesDb } = useFirebase()
14+
const { getLangMessages, getThemes, getGuessesDb, getLastVersion } =
15+
useFirebase()
1416

1517
const filterListByTitle = (list: Guess[], past: string[]) => {
1618
const filtered = list.filter((n) => !past.includes(n.title))
1719
return filtered
1820
}
21+
interface Version {
22+
version: string
23+
path: string
24+
folder: string
25+
}
1926

2027
export const useMainStore = defineStore('main', {
2128
// other options...
2229
state: () => ({
2330
error: false,
2431
loading: false,
25-
version: '',
32+
lastVersion: {
33+
version: '',
34+
path: '',
35+
folder: '',
36+
} as Version,
37+
versions: [] as Version[],
2638
lastUpdate: '',
2739
initialized: false,
2840
currentPath: '/home',
@@ -66,7 +78,11 @@ export const useMainStore = defineStore('main', {
6678
return
6779
this.loading = true
6880
try {
69-
await Promise.all([this.initLangMessages(), this.initThemes()])
81+
await Promise.all([
82+
this.initLangMessages(),
83+
this.initThemes(),
84+
this.getLastVersion(),
85+
])
7086
await this.initGuessTheme()
7187
this.initialized = true
7288
} catch (err: any) {
@@ -76,6 +92,15 @@ export const useMainStore = defineStore('main', {
7692
this.lastUpdate = new Date().toISOString()
7793
this.loading = false
7894
},
95+
async getLastVersion() {
96+
const newVersion = await getLastVersion()
97+
if (newVersion.version !== this.lastVersion.version) {
98+
this.lastVersion.version = newVersion.version
99+
this.lastVersion.path = newVersion.versionPath
100+
this.lastVersion.folder = ''
101+
this.versions.push(this.lastVersion)
102+
}
103+
},
79104
async initGuessTheme() {
80105
this.guessDb = await getGuessesDb(this.themes, this.lang)
81106
},

src/views/Game.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,7 @@
486486
const setupCanvas = () => {
487487
const options = {
488488
useWorker: true,
489-
resize: true,
490-
}
491-
if (isPlatform('android') && isPlatform('capacitor')) {
492-
options.resize = false
489+
resize: !isPlatform('android'),
493490
}
494491
confetti = createConfetti(null as unknown as HTMLCanvasElement, options)
495492
}

0 commit comments

Comments
 (0)