mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Save panel, when it's enabled in the settings.
This commit is contained in:
parent
11a1c4a6e7
commit
c77233f07d
3 changed files with 61 additions and 6 deletions
|
|
@ -21,37 +21,48 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
<template>
|
||||
<div id="panel-view">
|
||||
<div class="panel-preview__content" ref="panelView" v-html="viewPanel.html"></div>
|
||||
<div class="panel-container" ref="panelContainer" v-html="viewPanel.html"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { isLocal } from '@/services/ApiService'
|
||||
import { RunMacro } from '@/services/MacroService'
|
||||
import {
|
||||
CheckLocalPanel,
|
||||
PanelButtonListeners,
|
||||
PanelDialogListeners,
|
||||
RemovePanelScripts,
|
||||
RemovePanelStyle,
|
||||
SavePanelToLocal,
|
||||
SetPanelStyle,
|
||||
StripPanelHTML,
|
||||
} from '@/services/PanelService'
|
||||
import { usePanelStore } from '@/stores/panel'
|
||||
import { useSettingStore } from '@/stores/settings'
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
const panel = usePanelStore()
|
||||
const settings = useSettingStore()
|
||||
|
||||
const props = defineProps({
|
||||
dirname: String,
|
||||
})
|
||||
|
||||
const panelView = ref(null)
|
||||
const panelContainer = ref(null)
|
||||
|
||||
const viewPanel = ref({})
|
||||
|
||||
const wakeLock = ref(null)
|
||||
|
||||
onMounted(async () => {
|
||||
requestWakeLock()
|
||||
|
||||
const currentPanel = await panel.get(props.dirname)
|
||||
viewPanel.value = currentPanel
|
||||
|
||||
if (!isLocal() && settings.get('openLastPanel') && !CheckLocalPanel()) SavePanelToLocal()
|
||||
|
||||
viewPanel.value.html = StripPanelHTML(viewPanel.value.html, viewPanel.value.aspectRatio)
|
||||
SetPanelStyle(viewPanel.value.style)
|
||||
|
||||
|
|
@ -67,6 +78,8 @@ onMounted(async () => {
|
|||
onUnmounted(() => {
|
||||
RemovePanelStyle()
|
||||
RemovePanelScripts()
|
||||
|
||||
wakeLock.value.release()
|
||||
})
|
||||
|
||||
const viewPanelListeners = () => {
|
||||
|
|
@ -74,8 +87,20 @@ const viewPanelListeners = () => {
|
|||
RunMacro(viewPanel.value.macros[button.id])
|
||||
}
|
||||
|
||||
PanelButtonListeners(panelView.value, callback)
|
||||
PanelDialogListeners(panelView.value)
|
||||
PanelButtonListeners(panelContainer.value, callback)
|
||||
PanelDialogListeners(panelContainer.value)
|
||||
}
|
||||
|
||||
const requestWakeLock = async () => {
|
||||
try {
|
||||
if ('wakeLock' in navigator) {
|
||||
wakeLock.value = await navigator.wakeLock.request('screen')
|
||||
} else {
|
||||
console.warn('Wake Lock API not supported')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`${err.name}, ${err.message}`)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -88,7 +113,7 @@ const viewPanelListeners = () => {
|
|||
size-full
|
||||
bg-black;
|
||||
|
||||
.panel-preview__content {
|
||||
.panel-container {
|
||||
@apply relative
|
||||
grid
|
||||
justify-center
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { useNoticationStore } from '@/stores/notifications'
|
||||
|
||||
export const SetPanelStyle = (styleStr) => {
|
||||
const styleEl = document.createElement('style')
|
||||
styleEl.setAttribute('custom_panel_style', true)
|
||||
|
|
@ -118,3 +120,32 @@ export const PanelDialogListeners = (panelEl) => {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
const getPanelUrl = () => {
|
||||
const url = new URL(window.location.href)
|
||||
return url.pathname
|
||||
}
|
||||
|
||||
export const SavePanelToLocal = () => {
|
||||
localStorage.setItem('last_opened_panel', getPanelUrl())
|
||||
|
||||
const notificationStore = useNoticationStore()
|
||||
|
||||
notificationStore.add({
|
||||
message: 'Panel will be opened next launch',
|
||||
variant: 'success',
|
||||
time: 1000,
|
||||
})
|
||||
}
|
||||
|
||||
export const CheckLocalPanel = () => {
|
||||
const localPanel = localStorage.getItem('last_opened_panel')
|
||||
|
||||
if (localPanel) return localPanel == getPanelUrl()
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export const GetLocalPanel = () => {
|
||||
return localStorage.getItem('last_opened_panel')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ import ButtonComp from '@/components/base/ButtonComp.vue'
|
|||
import PanelEdit from '@/components/panels/PanelEdit.vue'
|
||||
import PanelView from '@/components/panels/PanelView.vue'
|
||||
import PanelsOverview from '@/components/panels/PanelsOverview.vue'
|
||||
import { isLocal } from '@/services/ApiService'
|
||||
import { IconArrowLeft } from '@tabler/icons-vue'
|
||||
import { onMounted, onUpdated, reactive } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue