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>
|
<template>
|
||||||
<div id="panel-view">
|
<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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { isLocal } from '@/services/ApiService'
|
||||||
import { RunMacro } from '@/services/MacroService'
|
import { RunMacro } from '@/services/MacroService'
|
||||||
import {
|
import {
|
||||||
|
CheckLocalPanel,
|
||||||
PanelButtonListeners,
|
PanelButtonListeners,
|
||||||
PanelDialogListeners,
|
PanelDialogListeners,
|
||||||
RemovePanelScripts,
|
RemovePanelScripts,
|
||||||
RemovePanelStyle,
|
RemovePanelStyle,
|
||||||
|
SavePanelToLocal,
|
||||||
SetPanelStyle,
|
SetPanelStyle,
|
||||||
StripPanelHTML,
|
StripPanelHTML,
|
||||||
} from '@/services/PanelService'
|
} from '@/services/PanelService'
|
||||||
import { usePanelStore } from '@/stores/panel'
|
import { usePanelStore } from '@/stores/panel'
|
||||||
|
import { useSettingStore } from '@/stores/settings'
|
||||||
import { onMounted, onUnmounted, ref } from 'vue'
|
import { onMounted, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
const panel = usePanelStore()
|
const panel = usePanelStore()
|
||||||
|
const settings = useSettingStore()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
dirname: String,
|
dirname: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
const panelView = ref(null)
|
const panelContainer = ref(null)
|
||||||
|
|
||||||
const viewPanel = ref({})
|
const viewPanel = ref({})
|
||||||
|
|
||||||
|
const wakeLock = ref(null)
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
requestWakeLock()
|
||||||
|
|
||||||
const currentPanel = await panel.get(props.dirname)
|
const currentPanel = await panel.get(props.dirname)
|
||||||
viewPanel.value = currentPanel
|
viewPanel.value = currentPanel
|
||||||
|
|
||||||
|
if (!isLocal() && settings.get('openLastPanel') && !CheckLocalPanel()) SavePanelToLocal()
|
||||||
|
|
||||||
viewPanel.value.html = StripPanelHTML(viewPanel.value.html, viewPanel.value.aspectRatio)
|
viewPanel.value.html = StripPanelHTML(viewPanel.value.html, viewPanel.value.aspectRatio)
|
||||||
SetPanelStyle(viewPanel.value.style)
|
SetPanelStyle(viewPanel.value.style)
|
||||||
|
|
||||||
|
|
@ -67,6 +78,8 @@ onMounted(async () => {
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
RemovePanelStyle()
|
RemovePanelStyle()
|
||||||
RemovePanelScripts()
|
RemovePanelScripts()
|
||||||
|
|
||||||
|
wakeLock.value.release()
|
||||||
})
|
})
|
||||||
|
|
||||||
const viewPanelListeners = () => {
|
const viewPanelListeners = () => {
|
||||||
|
|
@ -74,8 +87,20 @@ const viewPanelListeners = () => {
|
||||||
RunMacro(viewPanel.value.macros[button.id])
|
RunMacro(viewPanel.value.macros[button.id])
|
||||||
}
|
}
|
||||||
|
|
||||||
PanelButtonListeners(panelView.value, callback)
|
PanelButtonListeners(panelContainer.value, callback)
|
||||||
PanelDialogListeners(panelView.value)
|
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>
|
</script>
|
||||||
|
|
||||||
|
|
@ -88,7 +113,7 @@ const viewPanelListeners = () => {
|
||||||
size-full
|
size-full
|
||||||
bg-black;
|
bg-black;
|
||||||
|
|
||||||
.panel-preview__content {
|
.panel-container {
|
||||||
@apply relative
|
@apply relative
|
||||||
grid
|
grid
|
||||||
justify-center
|
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/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { useNoticationStore } from '@/stores/notifications'
|
||||||
|
|
||||||
export const SetPanelStyle = (styleStr) => {
|
export const SetPanelStyle = (styleStr) => {
|
||||||
const styleEl = document.createElement('style')
|
const styleEl = document.createElement('style')
|
||||||
styleEl.setAttribute('custom_panel_style', true)
|
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 PanelEdit from '@/components/panels/PanelEdit.vue'
|
||||||
import PanelView from '@/components/panels/PanelView.vue'
|
import PanelView from '@/components/panels/PanelView.vue'
|
||||||
import PanelsOverview from '@/components/panels/PanelsOverview.vue'
|
import PanelsOverview from '@/components/panels/PanelsOverview.vue'
|
||||||
import { isLocal } from '@/services/ApiService'
|
|
||||||
import { IconArrowLeft } from '@tabler/icons-vue'
|
import { IconArrowLeft } from '@tabler/icons-vue'
|
||||||
import { onMounted, onUpdated, reactive } from 'vue'
|
import { onMounted, onUpdated, reactive } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue