A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 79 lines 3.1 kB view raw
1import {App} from "../index"; 2import {Plugin} from "../plugin"; 3/// #if !MOBILE 4import {getAllModels} from "../layout/getAll"; 5import {resizeTopBar} from "../layout/util"; 6/// #endif 7import {Constants} from "../constants"; 8import {setStorageVal} from "../protyle/util/compatibility"; 9import {getAllEditor} from "../layout/getAll"; 10 11export const uninstall = (app: App, name: string, isUninstall = false) => { 12 app.plugins.find((plugin: Plugin, index) => { 13 if (plugin.name === name) { 14 // rm command 15 try { 16 plugin.onunload(); 17 if (isUninstall) { 18 plugin.uninstall(); 19 window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {}; 20 setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]); 21 } 22 } catch (e) { 23 console.error(`plugin ${plugin.name} onunload error:`, e); 24 } 25 // rm tab 26 /// #if !MOBILE 27 const modelsKeys = Object.keys(plugin.models); 28 getAllModels().custom.forEach(custom => { 29 if (modelsKeys.includes(custom.type)) { 30 custom.parent.parent.removeTab(custom.parent.id); 31 } 32 }); 33 /// #endif 34 // rm topBar 35 for (let i = 0; i < plugin.topBarIcons.length; i++) { 36 const item = plugin.topBarIcons[i]; 37 item.remove(); 38 plugin.topBarIcons.splice(i, 1); 39 i--; 40 } 41 /// #if !MOBILE 42 resizeTopBar(); 43 // rm statusBar 44 plugin.statusBarIcons.forEach(item => { 45 item.remove(); 46 }); 47 /// #endif 48 // rm dock 49 const docksKeys = Object.keys(plugin.docks); 50 docksKeys.forEach(key => { 51 if (Object.keys(window.siyuan.layout.leftDock.data).includes(key)) { 52 window.siyuan.layout.leftDock.remove(key); 53 } else if (Object.keys(window.siyuan.layout.rightDock.data).includes(key)) { 54 window.siyuan.layout.rightDock.remove(key); 55 } else if (Object.keys(window.siyuan.layout.bottomDock.data).includes(key)) { 56 window.siyuan.layout.bottomDock.remove(key); 57 } 58 }); 59 // rm listen 60 Array.from(document.childNodes).find(item => { 61 if (item.nodeType === 8 && item.textContent === name) { 62 item.remove(); 63 return true; 64 } 65 }); 66 // rm plugin 67 app.plugins.splice(index, 1); 68 // rm icons 69 document.querySelector(`svg[data-name="${plugin.name}"]`)?.remove(); 70 // rm protyle toolbar 71 getAllEditor().forEach(editor => { 72 editor.protyle.toolbar.update(editor.protyle); 73 }); 74 // rm style 75 document.getElementById("pluginsStyle" + name)?.remove(); 76 return true; 77 } 78 }); 79};