File tree Expand file tree Collapse file tree 5 files changed +40
-12
lines changed
Expand file tree Collapse file tree 5 files changed +40
-12
lines changed Original file line number Diff line number Diff line change 99</template >
1010<script setup lang="ts">
1111import { darkTheme } from " naive-ui" ;
12- import usePluginEnter from " ./composables/usePluginEnter" ;
13- const isDark = ref (false );
12+ const isDark = useDark ()
1413const theme = computed <typeof darkTheme | null >(() => {
1514 return isDark .value ? darkTheme : null
1615})
17- usePluginEnter (()=> {
18- isDark .value = window ?.utools .isDarkColors ()
19- })
16+
2017 </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 " ;
67+ import useUtools from " ../composeables/useUtools " ;
6868const message = useMessage ();
69+ const utools = useUtools ()
6970
7071const { ctrl_alt } = useMagicKeys ();
7172
@@ -82,7 +83,7 @@ const handleCopy = async () => {
8283 await copy (content );
8384 message .success (" 复制成功" );
8485 nextTick (() => {
85- utools . value ?.hideMainWindow ();
86+ utools ?.hideMainWindow ();
8687 });
8788};
8889// https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js
@@ -187,11 +188,6 @@ const handleClear = () => {
187188 body .value = " " ;
188189 type .value = typeOptions .value [0 ].value ;
189190};
190- const utools = ref <UToolsApi | null >(null );
191-
192- usePluginEnter (() => {
193- utools .value = window ?.utools
194- })
195191
196192 </script >
197193<style scoped>
Original file line number Diff line number Diff line change 1+ import { Ref } from "vue" ;
2+ import usePluginEnter from "./usePluginEnter" ;
3+
4+ export default function useDark ( ) : Ref < boolean > {
5+ const isDark = ref < boolean > ( false ) ;
6+ usePluginEnter ( ( ) => {
7+ isDark . value = window ?. utools . isDarkColors ( ) ;
8+ } ) ;
9+ return isDark ;
10+ }
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+ }
Original file line number Diff line number Diff line change 1+ import usePluginEnter from "./usePluginEnter" ;
2+
3+ export default function useUtools ( ) {
4+ let tools = reactive < UToolsApi > ( window ?. utools ) ;
5+ usePluginEnter ( ( ) => {
6+ tools = window ! . utools ;
7+ } ) ;
8+ return tools ;
9+ }
10+
You can’t perform that action at this time.
0 commit comments