Compare commits
3 Commits
cal/dev-21
...
alex/surve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c152229b0c | ||
|
|
fbbe6c70e9 | ||
|
|
2989d6e937 |
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
<script src="https://tally.so/widgets/embed.js" async></script>
|
||||||
<script type="module" src="/src/main.js"></script>
|
<script type="module" src="/src/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ import { openUrl } from '@tauri-apps/plugin-opener'
|
|||||||
import QuickInstanceSwitcher from '@/components/ui/QuickInstanceSwitcher.vue'
|
import QuickInstanceSwitcher from '@/components/ui/QuickInstanceSwitcher.vue'
|
||||||
import { get_available_capes, get_available_skins } from './helpers/skins'
|
import { get_available_capes, get_available_skins } from './helpers/skins'
|
||||||
import { generateSkinPreviews } from './helpers/rendering/batch-skin-renderer'
|
import { generateSkinPreviews } from './helpers/rendering/batch-skin-renderer'
|
||||||
|
import { list } from '@/helpers/profile.js'
|
||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
|
||||||
const themeStore = useTheming()
|
const themeStore = useTheming()
|
||||||
|
|
||||||
@@ -219,6 +221,8 @@ async function setupApp() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to generate skin previews in app setup.', error)
|
console.warn('Failed to generate skin previews in app setup.', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await processPendingSurveys()
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateFailed = ref(false)
|
const stateFailed = ref(false)
|
||||||
@@ -393,6 +397,91 @@ function handleAuxClick(e) {
|
|||||||
e.target.dispatchEvent(event)
|
e.target.dispatchEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanupOldSurveyDisplayData() {
|
||||||
|
const threeWeeksAgo = new Date()
|
||||||
|
threeWeeksAgo.setDate(threeWeeksAgo.getDate() - 21)
|
||||||
|
|
||||||
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
|
const key = localStorage.key(i)
|
||||||
|
|
||||||
|
if (key.startsWith('survey-') && key.endsWith('-display')) {
|
||||||
|
const dateValue = new Date(localStorage.getItem(key))
|
||||||
|
if (dateValue < threeWeeksAgo) {
|
||||||
|
localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processPendingSurveys() {
|
||||||
|
function isWithinLastTwoWeeks(date) {
|
||||||
|
const twoWeeksAgo = new Date()
|
||||||
|
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14)
|
||||||
|
return date >= twoWeeksAgo
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanupOldSurveyDisplayData()
|
||||||
|
|
||||||
|
const creds = await getCreds().catch(handleError)
|
||||||
|
const userId = creds?.user_id
|
||||||
|
|
||||||
|
const instances = await list().catch(handleError)
|
||||||
|
const isActivePlayer =
|
||||||
|
instances.findIndex(
|
||||||
|
(instance) =>
|
||||||
|
isWithinLastTwoWeeks(instance.last_played) && !isWithinLastTwoWeeks(instance.created),
|
||||||
|
) >= 0
|
||||||
|
|
||||||
|
let surveys = []
|
||||||
|
try {
|
||||||
|
surveys = await $fetch('https://api.modrinth.com/v2/surveys')
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error fetching surveys:', e)
|
||||||
|
}
|
||||||
|
|
||||||
|
const surveyToShow = surveys.find(
|
||||||
|
(survey) =>
|
||||||
|
localStorage.getItem(`survey-${survey.id}-display`) === null &&
|
||||||
|
survey.type === 'tally_app' &&
|
||||||
|
((survey.condition === 'active_player' && isActivePlayer) ||
|
||||||
|
(survey.assigned_users?.includes(userId) && !survey.dismissed_users?.includes(userId))),
|
||||||
|
)
|
||||||
|
|
||||||
|
if (surveyToShow) {
|
||||||
|
const formId = surveyToShow.tally_id
|
||||||
|
|
||||||
|
const popupOptions = {
|
||||||
|
layout: 'modal',
|
||||||
|
width: 700,
|
||||||
|
autoClose: 2000,
|
||||||
|
hideTitle: true,
|
||||||
|
hiddenFields: {
|
||||||
|
user_id: userId,
|
||||||
|
},
|
||||||
|
onOpen: () => console.info('Opened user survey'),
|
||||||
|
onClose: () => console.info('Closed user survey'),
|
||||||
|
onSubmit: () => console.info('Active user survey submitted'),
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (window.Tally?.openPopup) {
|
||||||
|
console.info(`Opening Tally popup for user survey (form ID: ${formId})`)
|
||||||
|
localStorage.setItem(`survey-${surveyToShow.id}-display`, new Date())
|
||||||
|
window.Tally.openPopup(formId, popupOptions)
|
||||||
|
} else {
|
||||||
|
console.warn('Tally script not yet loaded')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error opening Tally popup:', e)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.info(`Found user survey to show with tally_id: ${formId}`)
|
||||||
|
window.Tally.openPopup(formId, popupOptions)
|
||||||
|
} else {
|
||||||
|
console.info('No user survey to show')
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -90,8 +90,8 @@
|
|||||||
"font-src": ["https://cdn-raw.modrinth.com/fonts/"],
|
"font-src": ["https://cdn-raw.modrinth.com/fonts/"],
|
||||||
"img-src": "https: 'unsafe-inline' 'self' asset: http://asset.localhost http://textures.minecraft.net blob: data:",
|
"img-src": "https: 'unsafe-inline' 'self' asset: http://asset.localhost http://textures.minecraft.net blob: data:",
|
||||||
"style-src": "'unsafe-inline' 'self'",
|
"style-src": "'unsafe-inline' 'self'",
|
||||||
"script-src": "https://*.posthog.com 'self'",
|
"script-src": "https://*.posthog.com https://tally.so/widgets/embed.js 'self'",
|
||||||
"frame-src": "https://www.youtube.com https://www.youtube-nocookie.com https://discord.com 'self'",
|
"frame-src": "https://www.youtube.com https://www.youtube-nocookie.com https://discord.com https://tally.so/popup/ 'self'",
|
||||||
"media-src": "https://*.githubusercontent.com"
|
"media-src": "https://*.githubusercontent.com"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user