fullscreen.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <script setup lang="ts">
  2. /* Initialize stores. */
  3. import { useProfileStore } from '@/stores/profile'
  4. import { useSystemStore } from '@/stores/system'
  5. const Profile = useProfileStore()
  6. const System = useSystemStore()
  7. onBeforeMount(() => {
  8. // TODO Move this block to @nexajs/app
  9. try {
  10. Profile.$state = JSON.parse(localStorage.getItem('profile'), (key, value) => {
  11. if (typeof value === 'string' && /^\d+n$/.test(value)) {
  12. return BigInt(value.slice(0, value.length - 1))
  13. }
  14. return value
  15. })
  16. System.$state = JSON.parse(localStorage.getItem('system'), (key, value) => {
  17. if (typeof value === 'string' && /^\d+n$/.test(value)) {
  18. return BigInt(value.slice(0, value.length - 1))
  19. }
  20. return value
  21. })
  22. // add additional states here...
  23. } catch (err) {
  24. console.error(err)
  25. }
  26. })
  27. // TODO Move this block to @nexajs/app
  28. watch([Profile.$state, System.$state], (_state) => {
  29. localStorage.setItem('profile',
  30. JSON.stringify(_state[0], (key, value) =>
  31. typeof value === 'bigint' ? value.toString() + 'n' : value
  32. )
  33. )
  34. localStorage.setItem('system',
  35. JSON.stringify(_state[1], (key, value) =>
  36. typeof value === 'bigint' ? value.toString() + 'n' : value
  37. )
  38. )
  39. // watch additional states here...
  40. })
  41. onMounted(() => {
  42. /* Initailize system. */
  43. System.init()
  44. })
  45. onBeforeUnmount(() => {
  46. console.log('TODO! Cleanup session.')
  47. // Now is the time to perform all cleanup operations.
  48. })
  49. </script>
  50. <template>
  51. <main>
  52. <slot />
  53. </main>
  54. </template>