File size: 4,775 Bytes
0070fce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
<script setup lang="ts">
import { onMounted, watch } from 'vue'
import { getGlobalSetting, setAppFeSetting } from './api'
import { useGlobalStore, presistKeys } from './store/useGlobalStore'
import { useWorkspeaceSnapshot } from './store/useWorkspeaceSnapshot'
import { getQuickMovePaths } from '@/page/taskRecord/autoComplete'
import SplitViewTab from '@/page/SplitViewTab/SplitViewTab.vue'
import { Dict, createReactiveQueue, globalEvents, useGlobalEventListen } from './util'
import { resolveQueryActions } from './queryActions'
import { refreshTauriConf, tauriConf } from './util/tauriAppConf'
import { openModal } from './taurilaunchModal'
import { isTauri } from './util/env'
import { delay } from 'vue3-ts-util'
import { exportFn } from './defineExportFunc'
import { debounce, once, cloneDeep } from 'lodash-es'
import { message } from 'ant-design-vue'
import { t } from './i18n'
const globalStore = useGlobalStore()
const wsStore = useWorkspeaceSnapshot()
const queue = createReactiveQueue()
const presistKeysFiltered = presistKeys.filter(v => !['tabListHistoryRecord', 'recent'].includes(v))
let lastConf = null as any
const watchGlobalSettingChange = once(async () => {
globalStore.$subscribe((debounce(async () => {
if (globalStore.conf?.is_readonly === true) {
return
}
const conf = {} as Dict
presistKeysFiltered.forEach((key) => {
conf[key] = cloneDeep((globalStore as any)[key])
})
if (JSON.stringify(conf) === JSON.stringify(lastConf)) {
return
}
console.log('save global setting', conf)
await setAppFeSetting('global', conf)
lastConf = cloneDeep(conf)
}, 500)))
})
const restoreWorkspaceSnapshot = once( async () => {
await delay(100)
const initPage = globalStore.defaultInitinalPage
if (initPage === 'empty') {
return
}
if (initPage === 'last-workspace-state') {
const last = globalStore.tabListHistoryRecord?.[1]
if (!last?.tabs) {
return
}
globalStore.tabList = cloneDeep(last.tabs)
message.success(t('restoreLastWorkspaceStateSuccess'))
} else {
const id = initPage.split('_')?.[2]
const shot = wsStore.snapshots.find(v => v.id === id)
if (!shot?.tabs) {
return
}
globalStore.tabList = cloneDeep(shot.tabs)
message.success(t('restoreWorkspaceSnapshotSuccess'))
}
})
useGlobalEventListen('updateGlobalSetting', async () => {
await refreshTauriConf()
console.log(tauriConf.value)
const resp = await getGlobalSetting()
globalStore.conf = resp
const r = await getQuickMovePaths(resp)
globalStore.quickMovePaths = r.filter((v) => v?.dir?.trim?.())
const restoreFeGlobalSetting = globalStore?.conf?.app_fe_setting?.global
if (restoreFeGlobalSetting) {
console.log('restoreFeGlobalSetting', restoreFeGlobalSetting)
lastConf = cloneDeep(restoreFeGlobalSetting)
presistKeysFiltered.forEach((key) => {
const v = restoreFeGlobalSetting[key]
if (v !== undefined) {
(globalStore as any)[key] = v
}
})
}
watchGlobalSettingChange()
restoreWorkspaceSnapshot()
exportFn(globalStore)
resolveQueryActions(globalStore)
// globalEvents.emit('updateGlobalSettingDone')
})
useGlobalEventListen('returnToIIB', async () => {
const conf = globalStore.conf
if (!conf) {
return
}
const gs = conf.global_setting
if (!gs.outdir_txt2img_samples && !gs.outdir_img2img_samples) {
return
}
const set = new Set(globalStore.quickMovePaths.map(v => v.key))
if (set.has('outdir_txt2img_samples') && set.has('outdir_img2img_samples')) {
return
}
const r = await getQuickMovePaths(conf)
globalStore.quickMovePaths = r.filter((v) => v?.dir?.trim?.())
})
watch(
() => globalStore.computedTheme === 'dark',
async (enableDark) => {
await delay()
const head = document.getElementsByTagName('html')[0] // html而不是head保证优先级
if (enableDark) {
document.body.classList.add('dark')
const darkStyle = document.createElement('style')
const { default: css } = await import('ant-design-vue/dist/antd.dark.css?inline')
darkStyle.innerHTML = css
darkStyle.setAttribute('antd-dark', '')
head.appendChild(darkStyle)
} else {
document.body.classList.remove('dark')
Array.from(head.querySelectorAll('style[antd-dark]')).forEach((e) => e.remove())
}
},
{ immediate: true }
)
watch(() => globalStore.previewBgOpacity, (v) => {
document.documentElement.style.setProperty('--iib-preview-mask-bg', `rgba(0, 0, 0, ${v})`)
}, { immediate: true })
onMounted(async () => {
if (isTauri) {
openModal()
}
globalEvents.emit('updateGlobalSetting')
})
</script>
<template>
<a-skeleton :loading="!queue.isIdle">
<SplitViewTab />
</a-skeleton>
</template>
|