parent
655ec1fd28
commit
0d59864121
4 changed files with 56 additions and 17 deletions
@ -1,24 +1,15 @@ |
|||||||
import { spawnSync } from 'node:child_process'; |
|
||||||
import withSerwistInit from '@serwist/next'; |
import withSerwistInit from '@serwist/next'; |
||||||
|
import { format } from 'date-fns'; |
||||||
// This is optional!
|
|
||||||
// A revision helps Serwist version a precached page. This
|
|
||||||
// avoids outdated precached responses being used. Using
|
|
||||||
// `git rev-parse HEAD` might not the most efficient way
|
|
||||||
// of determining a revision, however. You may prefer to use
|
|
||||||
// the hashes of every extra file you precache.
|
|
||||||
const revision = |
|
||||||
spawnSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf-8' }).stdout ?? |
|
||||||
crypto.randomUUID(); |
|
||||||
|
|
||||||
const withSerwist = withSerwistInit({ |
const withSerwist = withSerwistInit({ |
||||||
additionalPrecacheEntries: [{ url: '/~offline', revision }], |
additionalPrecacheEntries: [{ url: '/~offline' }], |
||||||
// Note: This is only an example. If you use Pages Router,
|
|
||||||
// use something else that works, such as "service-worker/index.ts".
|
|
||||||
swSrc: 'app/sw.ts', |
swSrc: 'app/sw.ts', |
||||||
swDest: 'public/sw.js', |
swDest: 'public/sw.js', |
||||||
}); |
}); |
||||||
|
|
||||||
export default withSerwist({ |
export default withSerwist({ |
||||||
// Your Next.js config
|
env: { |
||||||
|
APP_VERSION: `Ver. ${format(new Date(), 'yy.MM.dd-HHmm')}`, |
||||||
|
}, |
||||||
|
output: 'standalone', |
||||||
}); |
}); |
||||||
|
|||||||
@ -0,0 +1,32 @@ |
|||||||
|
import { create } from 'zustand'; |
||||||
|
import { persist } from 'zustand/middleware'; |
||||||
|
|
||||||
|
type SettingsState = { |
||||||
|
hasHydrated: boolean; |
||||||
|
setHasHydrated: (v: boolean) => void; |
||||||
|
devMode: boolean; |
||||||
|
setDevMode: (mode: boolean) => void; |
||||||
|
id: string; |
||||||
|
setId: (id: string) => void; |
||||||
|
}; |
||||||
|
|
||||||
|
export const useSettingsStore = create<SettingsState>()( |
||||||
|
persist( |
||||||
|
(set) => ({ |
||||||
|
hasHydrated: false, |
||||||
|
setHasHydrated: (v) => set({ hasHydrated: v }), |
||||||
|
devMode: false, |
||||||
|
setDevMode: (mode) => set({ devMode: mode }), |
||||||
|
id: 'new-client', |
||||||
|
setId: (id) => set({ id }), |
||||||
|
}), |
||||||
|
{ |
||||||
|
name: 'settings-storage', |
||||||
|
onRehydrateStorage: () => (state) => { |
||||||
|
if (state) { |
||||||
|
state.setHasHydrated(true); |
||||||
|
} |
||||||
|
}, |
||||||
|
}, |
||||||
|
), |
||||||
|
); |
||||||
Loading…
Reference in new issue