1
1
<template >
2
2
<n-card bordered shadow =" always" >
3
- <n-tabs default-value =" video" justify-content =" space-evenly" type =" line" animated >
4
- <n-tab-pane name =" video" tab =" 摄像头" >
5
- <n-grid x-gap =" 12" :cols =" 2" >
6
- <n-gi >
7
- <p >摄像头服务:未启动</p >
8
- {{ cameraInfo }}
9
- <n-grid x-gap =" 12" :cols =" 2" >
10
- <n-gi >
11
- <n-button size =" small" type =" primary" >启动</n-button >
12
- </n-gi >
13
- <n-gi >
14
- <n-button size =" small" type =" error" >测试</n-button >
15
- </n-gi >
16
- </n-grid >
17
- </n-gi >
18
- <n-gi >
19
- <p >修改配置 <n-button size =" small" type =" primary" >保存</n-button ></p >
3
+ <n-grid x-gap =" 12" :cols =" 2" >
4
+ <n-gi >
5
+ <p >摄像头服务:<n-tag :type =" runCamera ? 'success' : 'error'" >{{ runCamera ? '运行中' : '未运行' }}</n-tag ></p >
6
+ {{ cameraInfo }}
7
+ <n-space >
8
+ <n-button size =" small" type =" primary" @click =" runService('vlc-webcam', 'restart')" >启动</n-button >
9
+ <n-button size =" small" type =" error" @click =" runService('vlc-webcam', 'stop')" >停止</n-button >
10
+ <n-button size =" small" type =" info" @click =" runVLC('webcam')" >测试</n-button >
11
+ <n-button size =" small" type =" warning" @click =" runService('vlc-webcam', 'enable')" >激活</n-button >
12
+ </n-space >
13
+ <p >屏幕捕获服务:<n-tag :type =" runScreen ? 'success' : 'error'" >{{ runScreen ? '运行中' : '未运行' }}</n-tag ></p >
14
+ {{ screenInfo }}
15
+ <n-space >
16
+ <n-button size =" small" type =" primary" @click =" runService('vlc-screen', 'restart')" >启动</n-button >
17
+ <n-button size =" small" type =" primary" @click =" runService('vlc-screen', 'stop')" >停止</n-button >
18
+ <n-button size =" small" type =" error" @click =" runVLC('screen')" >测试</n-button >
19
+ <n-button size =" small" type =" warning" @click =" runService('vlc-screen', 'enable')" >激活</n-button >
20
+ </n-space >
21
+ </n-gi >
22
+ <n-gi >
23
+ <n-tabs default-value =" video" justify-content =" space-evenly" type =" line" animated >
24
+ <n-tab-pane name =" video" tab =" 视频配置" >
20
25
<n-input type =" textarea" rows =" 4" placeholder =" 配置文件" v-model:value =" cameraInfo" ></n-input >
21
- </n-gi >
22
- </n-grid >
23
- </n-tab-pane >
24
- <n-tab-pane name =" desktop" tab =" 桌面" >
25
- <n-grid x-gap =" 12" :cols =" 2" >
26
- <n-gi >
27
- <p >屏幕捕获服务:未启动</p >
28
- {{ screenInfo }}
29
- <n-grid x-gap =" 12" :cols =" 2" >
30
- <n-gi >
31
- <n-button size =" small" type =" primary" >启动</n-button >
32
- </n-gi >
33
- <n-gi >
34
- <n-button size =" small" type =" error" >测试</n-button >
35
- </n-gi >
36
- </n-grid >
37
- </n-gi >
38
- <n-gi >
39
- <p >修改配置 <n-button size =" small" type =" primary" >保存</n-button ></p >
26
+ <n-button size =" small" block type =" primary" >保存</n-button >
27
+ </n-tab-pane >
28
+ <n-tab-pane name =" desktop" tab =" 桌面配置" >
40
29
<n-input type =" textarea" rows =" 4" placeholder =" 配置文件" v-model:value =" screenInfo" ></n-input >
41
- </n-gi >
42
- </n-grid >
43
- </n-tab-pane >
44
- </n-tabs >
30
+ <n-button size =" small" block type =" primary" >保存</n-button >
31
+ </n-tab-pane >
32
+ </n-tabs >
33
+ </n-gi >
34
+ </n-grid >
45
35
</n-card >
46
36
</template >
47
37
48
38
<script setup lang="ts">
49
- import { filesystem } from ' @neutralinojs/lib' ;
39
+ import { filesystem , os } from ' @neutralinojs/lib' ;
50
40
import { NCard , NGrid , NGi , NButton , NInput , NTabs , NTabPane } from ' naive-ui' ;
51
41
import { onMounted , ref } from ' vue' ;
52
42
43
+ const hasCamera = ref (false );
44
+
45
+ const runCamera = ref (false );
46
+ const runScreen = ref (false );
47
+
53
48
const cameraInfo = ref (' ' );
54
49
const screenInfo = ref (' ' );
55
- // const betterCameraInfo = ref({});
56
- // const betterScreenInfo = ref({});
50
+
51
+ const runService = async (service : string , action : string ) => {
52
+
53
+ try {
54
+ const res = await os .execCommand (` systemctl ${action } ${service } ` );
55
+ console .log (` systemctl ${action } ${service } status ` , res );
56
+ if (res .stdErr || res .exitCode ) throw new Error (res .stdErr );
57
+ if (action === ' restart' ) {
58
+ if (service === ' vlc-screen' ) runScreen .value = true ;
59
+ if (service === ' vlc-webcam' ) runCamera .value = true ;
60
+ } else {
61
+ if (service === ' vlc-screen' ) runScreen .value = false ;
62
+ if (service === ' vlc-webcam' ) runCamera .value = false ;
63
+ }
64
+ } catch (error ) {
65
+ console .error (error );
66
+ window .$notification .error ({ title: ' 操作失败' , content: (error as any ).message , duration: 3000 });
67
+ }
68
+ };
69
+
70
+ const runVLC = async (service : string ) => {
71
+ const port = service === ' webcam' ? ' 8080' : ' 9090' ;
72
+ try {
73
+ const res = await os .execCommand (` su icpc -c "vlc http://localhost:${port }/" ` );
74
+ console .log (' run vlc on test' , res );
75
+ if (res .stdErr || res .exitCode ) throw new Error (res .stdErr );
76
+ window .$notification .success ({ title: ' VLC启动成功' , content: ' 请查看VLC播放器,确认视频正常后关闭' , duration: 3000 });
77
+ } catch (error ) {
78
+ console .error (error );
79
+ window .$notification .error ({ title: ' VLC启动失败' , content: (error as any ).message , duration: 3000 });
80
+ }
81
+ }
57
82
58
83
59
84
onMounted (async () => {
60
85
try {
86
+ const checkCamera = await filesystem .readDirectory (' /dev' );
87
+ hasCamera .value = checkCamera .map ((item ) => item .path ).includes (' video0' );
61
88
const camera = await filesystem .readFile (' /etc/default/vlc-webcam' );
62
89
const screen = await filesystem .readFile (' /etc/default/vlc-screen' );
63
90
cameraInfo .value = camera ;
@@ -67,5 +94,15 @@ onMounted(async () => {
67
94
cameraInfo .value = ' no camera config found' ;
68
95
screenInfo .value = ' no screen config found' ;
69
96
}
97
+ try {
98
+ const res = await os .execCommand (' systemctl status vlc-screen' );
99
+ console .log (' systemctl status vlc-screen status' , res );
100
+ if (! res .stdOut .includes (' dead' )) runScreen .value = true ;
101
+ const res2 = await os .execCommand (' systemctl status vlc-webcam' );
102
+ console .log (' systemctl status vlc-webcam status' , res2 );
103
+ if (! res2 .stdOut .includes (' dead' )) runCamera .value = true ;
104
+ } catch (error ) {
105
+ console .error (error );
106
+ }
70
107
});
71
108
</script >
0 commit comments