refactor: move pwa/build-info -> appConfig (#1508)
This commit is contained in:
parent
1c9004a731
commit
415d36ce32
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
const buildInfo = useRuntimeConfig().public.buildInfo
|
||||
const buildInfo = useAppConfig().buildInfo
|
||||
const timeAgoOptions = useTimeAgoOptions()
|
||||
|
||||
const userSettings = useUserSettings()
|
||||
|
|
|
@ -17,7 +17,7 @@ const {
|
|||
} = usePushManager()
|
||||
const { t } = useI18n()
|
||||
|
||||
const pwaEnabled = useRuntimeConfig().public.pwaEnabled
|
||||
const pwaEnabled = useAppConfig().pwaEnabled
|
||||
|
||||
let busy = $ref<boolean>(false)
|
||||
let animateSave = $ref<boolean>(false)
|
||||
|
|
|
@ -35,5 +35,5 @@ export const teams: Team[] = [
|
|||
].sort(() => Math.random() - 0.5)
|
||||
|
||||
export function useBuildInfo() {
|
||||
return useRuntimeConfig().public.buildInfo as BuildInfo
|
||||
return useAppConfig().buildInfo as BuildInfo
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ export function setupPageHeader() {
|
|||
|
||||
return titleTemplate
|
||||
},
|
||||
link: process.client && useRuntimeConfig().public.pwaEnabled
|
||||
link: process.client && useAppConfig().pwaEnabled
|
||||
? () => [{
|
||||
key: 'webmanifest',
|
||||
rel: 'manifest',
|
||||
|
|
|
@ -149,7 +149,7 @@ export async function loginTo(masto: ElkMasto, user: Overwrite<UserLogin, { acco
|
|||
const [me, pushSubscription] = await Promise.all([
|
||||
fetchAccountInfo(client, user.server),
|
||||
// if PWA is not enabled, don't get push subscription
|
||||
useRuntimeConfig().public.pwaEnabled
|
||||
useAppConfig().pwaEnabled
|
||||
// we get 404 response instead empty data
|
||||
? client.v1.webPushSubscriptions.fetch().catch(() => Promise.resolve(undefined))
|
||||
: Promise.resolve(undefined),
|
||||
|
@ -194,7 +194,7 @@ export async function removePushNotificationData(user: UserLogin, fromSWPushMana
|
|||
// clear push notification policy
|
||||
delete useLocalStorage<PushNotificationPolicy>(STORAGE_KEY_NOTIFICATION_POLICY, {}).value[acct]
|
||||
|
||||
const pwaEnabled = useRuntimeConfig().public.pwaEnabled
|
||||
const pwaEnabled = useAppConfig().pwaEnabled
|
||||
const pwa = useNuxtApp().$pwa
|
||||
const registrationError = pwa?.registrationError === true
|
||||
const unregister = pwaEnabled && !registrationError && pwa?.registrationError === true && fromSWPushManager
|
||||
|
|
|
@ -19,8 +19,12 @@ export default defineNuxtModule({
|
|||
env,
|
||||
}
|
||||
|
||||
nuxt.options.runtimeConfig.public.env = env
|
||||
nuxt.options.runtimeConfig.public.buildInfo = buildInfo
|
||||
nuxt.options.appConfig = nuxt.options.appConfig || {}
|
||||
nuxt.options.appConfig.env = env
|
||||
nuxt.options.appConfig.buildInfo = buildInfo
|
||||
|
||||
nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {}
|
||||
nuxt.options.nitro.virtual['#build-info'] = `export const env = ${JSON.stringify(env)}`
|
||||
|
||||
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || []
|
||||
if (env === 'dev')
|
||||
|
|
|
@ -23,6 +23,9 @@ export default defineNuxtModule<VitePWANuxtOptions>({
|
|||
}
|
||||
let webmanifests: LocalizedWebManifest | undefined
|
||||
|
||||
nuxt.options.appConfig = nuxt.options.appConfig || {}
|
||||
nuxt.options.appConfig.pwaEnabled = !options.disable
|
||||
|
||||
// TODO: combine with configurePWAOptions?
|
||||
nuxt.hook('nitro:init', (nitro) => {
|
||||
options.outDir = nitro.options.output.publicDir
|
||||
|
|
|
@ -23,6 +23,7 @@ export default defineNuxtModule({
|
|||
'unstorage/drivers/fs': 'unenv/runtime/mock/proxy',
|
||||
'unstorage/drivers/cloudflare-kv-http': 'unenv/runtime/mock/proxy',
|
||||
'node:events': 'unenv/runtime/node/events/index',
|
||||
'#build-info': resolve('./runtime/build-info'),
|
||||
}
|
||||
|
||||
nuxt.hook('vite:extend', ({ config }) => {
|
||||
|
|
1
modules/tauri/runtime/build-info.ts
Normal file
1
modules/tauri/runtime/build-info.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export const env = useAppConfig().env
|
|
@ -4,7 +4,6 @@ import { isCI, isDevelopment, isWindows } from 'std-env'
|
|||
import { isPreview } from './config/env'
|
||||
import { i18n } from './config/i18n'
|
||||
import { pwa } from './config/pwa'
|
||||
import type { BuildInfo } from './types'
|
||||
|
||||
const { resolve } = createResolver(import.meta.url)
|
||||
|
||||
|
@ -96,10 +95,8 @@ export default defineNuxtConfig({
|
|||
},
|
||||
public: {
|
||||
privacyPolicyUrl: '',
|
||||
env: '', // set in build-env module
|
||||
buildInfo: {} as BuildInfo, // set in build-env module
|
||||
pwaEnabled: !isDevelopment || process.env.VITE_DEV_PWA === 'true',
|
||||
// We use LibreTranslate(https://github.com/LibreTranslate/LibreTranslate) as our default translation server #76
|
||||
// We use LibreTranslate (https://github.com/LibreTranslate/LibreTranslate) as
|
||||
// our default translation server #76
|
||||
translateApi: '',
|
||||
// Use the instance where Elk has its Mastodon account as the default
|
||||
defaultServer: 'm.webtoo.ls',
|
||||
|
|
|
@ -6,7 +6,7 @@ definePageMeta({
|
|||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
const pwaEnabled = useRuntimeConfig().public.pwaEnabled
|
||||
const pwaEnabled = useAppConfig().pwaEnabled
|
||||
|
||||
const tabs = $computed<CommonRouteTabOption[]>(() => [
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ definePageMeta({
|
|||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
const pwaEnabled = useRuntimeConfig().public.pwaEnabled
|
||||
const pwaEnabled = useAppConfig().pwaEnabled
|
||||
|
||||
useHeadFixed({
|
||||
title: () => `${t('settings.notifications.label')} | ${t('nav.settings')}`,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
definePageMeta({
|
||||
middleware: ['auth', () => {
|
||||
if (!useRuntimeConfig().public.pwaEnabled)
|
||||
if (!useAppConfig().pwaEnabled)
|
||||
return navigateTo('/settings/notifications')
|
||||
}],
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script setup>
|
||||
definePageMeta({
|
||||
middleware: () => {
|
||||
if (!useRuntimeConfig().public.pwaEnabled)
|
||||
if (!useAppConfig().pwaEnabled)
|
||||
return navigateTo('/')
|
||||
},
|
||||
})
|
||||
|
|
|
@ -12,6 +12,9 @@ import type { Storage } from 'unstorage'
|
|||
|
||||
import cached from './cache-driver'
|
||||
|
||||
// @ts-expect-error virtual import
|
||||
import { env } from '#build-info'
|
||||
|
||||
import type { AppInfo } from '~/types'
|
||||
import { APP_NAME } from '~/constants'
|
||||
|
||||
|
@ -45,7 +48,7 @@ async function fetchAppInfo(origin: string, server: string) {
|
|||
const app: AppInfo = await $fetch(`https://${server}/api/v1/apps`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
client_name: APP_NAME + (config.public.env !== 'release' ? ` (${config.public.env})` : ''),
|
||||
client_name: APP_NAME + (env !== 'release' ? ` (${env})` : ''),
|
||||
website: 'https://elk.zone',
|
||||
redirect_uris: getRedirectURI(origin, server),
|
||||
scopes: 'read write follow push',
|
||||
|
|
Loading…
Reference in a new issue