File tree Expand file tree Collapse file tree 3 files changed +26
-18
lines changed
Expand file tree Collapse file tree 3 files changed +26
-18
lines changed Original file line number Diff line number Diff line change 88 <NButton @click="theme = null">浅色</NButton> -->
99</template >
1010<script setup lang="ts">
11- import { onMounted , computed } from " vue" ;
1211import { darkTheme } from " naive-ui" ;
13- import { BuiltInGlobalTheme } from " naive-ui/lib/themes/interface " ;
12+ import usePluginEnter from " ./composables/usePluginEnter " ;
1413const isDark = ref (false );
15- const theme = computed <BuiltInGlobalTheme | null >(() => {
14+ const theme = computed <typeof darkTheme | null >(() => {
1615 return isDark .value ? darkTheme : null
1716})
18- let utools = null ;
19- onMounted (() => {
20- if (window [" utools" ]) {
21- utools = window [" utools" ];
22- utools .onPluginEnter (() => {
23- isDark .value = utools .isDarkColors ();
24- });
25- }
17+ usePluginEnter (()=> {
18+ isDark .value = window ?.utools .isDarkColors ()
2619})
2720 </script >
Original file line number Diff line number Diff line change 6464</template >
6565<script setup lang="ts">
6666import { useMessage } from " naive-ui" ;
67+ import usePluginEnter from " src/composables/usePluginEnter" ;
6768const message = useMessage ();
6869
6970const { ctrl_alt } = useMagicKeys ();
@@ -81,7 +82,7 @@ const handleCopy = async () => {
8182 await copy (content );
8283 message .success (" 复制成功" );
8384 nextTick (() => {
84- utools && utools .hideMainWindow ();
85+ utools . value ? .hideMainWindow ();
8586 });
8687};
8788// https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js
@@ -186,12 +187,11 @@ const handleClear = () => {
186187 body .value = " " ;
187188 type .value = typeOptions .value [0 ].value ;
188189};
189- let utools = null ;
190- onMounted (() => {
191- if (window [" utools" ]) {
192- utools = window [" utools" ];
193- }
194- });
190+ const utools = ref <UToolsApi | null >(null );
191+
192+ usePluginEnter (() => {
193+ utools .value = window ?.utools
194+ })
195195
196196 </script >
197197<style scoped>
Original file line number Diff line number Diff line change 1+ export interface IPluginEnterAction {
2+ code : string ;
3+ type : string ;
4+ payload : any ;
5+ }
6+
7+ export default function usePluginEnter (
8+ hook : ( action : IPluginEnterAction ) => unknown
9+ ) {
10+ onMounted ( ( ) => {
11+ window ?. utools . onPluginEnter ( ( action ) => {
12+ return hook ( action ) ;
13+ } ) ;
14+ } ) ;
15+ }
You can’t perform that action at this time.
0 commit comments