Skip to content

Commit

Permalink
chore: update pwa without prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
wolimst committed Aug 5, 2024
1 parent 645a443 commit bd3b9e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/Notification.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import SuccessIcon from './components/ui/icons/Success.svelte'
import EmojiDizzyIcon from '@/components/ui/icons/EmojiDizzy.svelte'
import SpinnerIcon from '@/components/ui/icons/Spinner.svelte'
import TrophyIcon from '@/components/ui/icons/Trophy.svelte'
import WarningIcon from '@/components/ui/icons/Warning.svelte'
import { ALERT_DURATION_MS } from '@/constants'
Expand Down Expand Up @@ -73,6 +74,12 @@
>
<SuccessIcon />
</div>
{:else if type === 'loading'}
<div
class="tw-w-5 tw-h-5 tw-inline-flex tw-justify-center tw-items-center tw-flex-shrink-0"
>
<SpinnerIcon width={22} />
</div>
{/if}

<div class="tw-ml-2.5 tw-text-sm">
Expand Down
31 changes: 16 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@ function skipInAppBrowser() {

const updateSW = registerSW({
onNeedRefresh() {
const answer = confirm('새로운 버전이 있어요. 업데이트를 적용할까요?')
if (answer) {
updateSW(true)
.then(() => {
config.update((config) => {
config.isBeingUpdated = true
return config
})
notification.set({
type: 'loading',
message: '새로운 업데이트가 있어요. 잠시만 기다려주세요.',
})
updateSW(true)
.then(() => {
config.update((config) => {
config.isBeingUpdated = true
return config
})
.catch((e) => {
notification.set({
type: 'error',
message: '앗, 업데이트에 실패했어요.',
})
console.error(e)
})
.catch((e) => {
notification.set({
type: 'error',
message: '앗, 업데이트에 실패했어요.',
})
}
console.error(e)
})
},
})

Expand Down
8 changes: 7 additions & 1 deletion src/stores/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export interface Config {
}

export interface Notification {
type?: 'error' | 'success' | 'wordle-win' | 'wordle-bonus-win' | 'wordle-loss'
type?:
| 'error'
| 'success'
| 'loading'
| 'wordle-win'
| 'wordle-bonus-win'
| 'wordle-loss'
message: string
}

0 comments on commit bd3b9e1

Please sign in to comment.