Skip to content

Commit

Permalink
feat: #319 PicGO图形化配置界面-移除事件注册
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Feb 17, 2023
1 parent c2322aa commit f26c481
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 7 additions & 1 deletion components/picgo/setting/PicgoConfigSetting.vue
Expand Up @@ -99,7 +99,7 @@
</template>

<script lang="ts" setup>
import { onBeforeMount, reactive, ref } from "vue"
import { onBeforeMount, onBeforeUnmount, reactive, ref } from "vue"
import picgoUtil from "~/utils/otherlib/picgoUtil"
import { LogFactory } from "~/utils/logUtil"
import siyuanBrowserUtil from "~/utils/otherlib/siyuanBrowserUtil"
Expand Down Expand Up @@ -199,6 +199,7 @@ function initData() {
}
}
// register events
onBeforeMount(() => {
picgoUtil.ipcRegisterEvent("getPicBeds", (evt, data) => {
getPicBeds()
Expand All @@ -209,4 +210,9 @@ onBeforeMount(() => {
initData()
})
// remove events
onBeforeUnmount(() => {
picgoUtil.ipcRemoveEvent("getPicBeds")
})
</script>
17 changes: 16 additions & 1 deletion components/picgo/setting/PicgoPluginSetting.vue
Expand Up @@ -157,7 +157,14 @@
import picgoUtil from "~/utils/otherlib/picgoUtil"
import { LogFactory } from "~/utils/logUtil"
import { ElMessage, ElMessageBox } from "element-plus"
import { computed, onBeforeMount, reactive, ref, watch } from "vue"
import {
computed,
onBeforeMount,
onBeforeUnmount,
reactive,
ref,
watch,
} from "vue"
import { goToPage } from "~/utils/otherlib/ChromeUtil"
import sysUtil from "~/utils/otherlib/sysUtil"
import { debounce, DebouncedFunc } from "lodash"
Expand Down Expand Up @@ -428,6 +435,14 @@ onBeforeMount(() => {
getPluginList()
getSearchResult = debounce(_getSearchResult, 50)
})
// remove events
onBeforeUnmount(() => {
picgoUtil.ipcRemoveEvent("pluginList")
picgoUtil.ipcRemoveEvent("installPluginFinished")
picgoUtil.ipcRemoveEvent("picgoHandlePluginIng")
picgoUtil.ipcRemoveEvent("uninstallSuccess")
})
</script>

<style lang="stylus">
Expand Down
13 changes: 13 additions & 0 deletions utils/otherlib/picgoUtil.js
Expand Up @@ -486,6 +486,18 @@ const ipcRegisterEvent = (channel, data = {}) => {
syPicgo.ipcMethods.registerEvent(channel, data)
}

/**
* 移除事件监听
*
* @param channel 频道
*/
const ipcRemoveEvent = (channel) => {
const syWin = siyuanBrowserUtil.getSiyuanWindow()
const syPicgo = syWin?.SyPicgo

syPicgo.ipcMethods.removeEvent(channel)
}

/**
* 构建插件菜单
*
Expand Down Expand Up @@ -554,6 +566,7 @@ const picgoUtil = {
// Ipc
ipcHandleEvent,
ipcRegisterEvent,
ipcRemoveEvent,

getPicgoVersion,

Expand Down

0 comments on commit f26c481

Please sign in to comment.