Skip to content

Commit b9aab59

Browse files
committed
machine-setup: add feature
1 parent 24a5dd0 commit b9aab59

File tree

4 files changed

+165
-2
lines changed

4 files changed

+165
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"packageManager": "[email protected]",
44
"private": true,
55
"workspaces": [
6-
"packages/*"
6+
"packages/*",
7+
"packages/machine-setup/frontend"
78
],
89
"scripts": {
910
"dev:client": "node -r ./register.js packages/server/index.ts --client --debug",

packages/machine-setup/frontend/src/App.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<n-gi>
1212
<system-info />
1313
<network-info />
14+
<n-card bordered shadow="always">
15+
<n-button type="primary" @click="checkAll" style="width: 100%;">完成设备检查</n-button>
16+
</n-card>
1417
</n-gi>
1518
</n-grid>
1619
</n-notification-provider>
@@ -19,7 +22,7 @@
1922

2023
<script setup lang="ts">
2124
import {
22-
NGrid, NGi, darkTheme, NConfigProvider, useOsTheme, NNotificationProvider,
25+
NGrid, NGi, darkTheme, NConfigProvider, useOsTheme, NButton, NCard, NNotificationProvider,
2326
} from 'naive-ui';
2427
import BasicInfo from './components/BasicInfo.vue';
2528
import HeartbeatInfo from './components/HeartbeatInfo.vue';
@@ -29,4 +32,8 @@ import VideoInfo from './components/VideoInfo.vue';
2932
import Provider from './components/Provider.vue';
3033
3134
const osTheme = useOsTheme();
35+
36+
const checkAll = () => {
37+
console.log('check all');
38+
};
3239
</script>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<template>
2+
<n-card bordered title="Machine Info" shadow="always">
3+
<n-grid x-gap="12" :cols="2">
4+
<n-gi>
5+
<p>CPU: {{ cpuInfo }}</p>
6+
<p>Mem: {{ memoryInfo }}</p>
7+
<p>OS: {{ osInfo }}</p>
8+
<p>Image Version: {{ imageVer }}</p>
9+
<p>Displays: {{ displaysInfo }}</p>
10+
</n-gi>
11+
<n-gi>
12+
<p>gcc: {{ gccVer }}</p>
13+
<p>g++: {{ gppVer }}</p>
14+
<p>java: {{ javaVer }}</p>
15+
<p>kotlin: {{ kotlinVer }}</p>
16+
<p>python3: {{ python3Ver }}</p>
17+
<p>pypy3: {{ pypy3Ver }}</p>
18+
</n-gi>
19+
</n-grid>
20+
</n-card>
21+
</template>
22+
23+
<script setup lang="ts">
24+
import { computer, filesystem, os } from '@neutralinojs/lib';
25+
import { onMounted, ref } from 'vue';
26+
27+
const osInfo = ref<string>('Loading...');
28+
const cpuInfo = ref<string>('Loading...');
29+
const memoryInfo = ref<string>('Loading...');
30+
const displaysInfo = ref<string>('Loading...');
31+
const imageVer = ref<string>('Loading...');
32+
33+
const gccVer = ref<string>('Loading...');
34+
const gppVer = ref<string>('Loading...');
35+
const javaVer = ref<string>('Loading...');
36+
const kotlinVer = ref<string>('Loading...');
37+
const python3Ver = ref<string>('Loading...');
38+
const pypy3Ver = ref<string>('Loading...');
39+
40+
const getVer = async (cmd: string, regexp?: string) => {
41+
try {
42+
const exec = await os.execCommand(`${cmd}`);
43+
if (regexp) {
44+
let match = exec.stdOut.match(new RegExp(regexp));
45+
if (!exec.stdOut || !match || !match.length) {
46+
match = exec.stdErr.match(new RegExp(regexp));
47+
}
48+
console.log(cmd, exec, match);
49+
return match ? match[0] : 'Not found';
50+
}
51+
return exec.stdOut;
52+
} catch (e) {
53+
return 'Not found';
54+
}
55+
}
56+
57+
onMounted(async () => {
58+
const [arch, kernel, os, cpu, memory, displays] = await Promise.all([
59+
computer.getArch(),
60+
computer.getKernelInfo(),
61+
computer.getOSInfo(),
62+
computer.getCPUInfo(),
63+
computer.getMemoryInfo(),
64+
computer.getDisplays(),
65+
]);
66+
osInfo.value = `${os.name} ${os.version} ${arch} - ${os.description}(${kernel.variant} ${kernel.version})`;
67+
cpuInfo.value = `${cpu.physicalCores}C${cpu.logicalThreads}T ${cpu.architecture} ${cpu.model} ${(cpu.frequency / 1024 / 1024 / 1024).toFixed(2)}GHz`;
68+
memoryInfo.value = `P: ${(memory.physical.available / 1024 / 1024 / 1024).toFixed(2)}GB/${(memory.physical.total / 1024 / 1024 / 1024).toFixed(2)}GB
69+
S: ${(memory.virtual.available / 1024 / 1024 / 1024).toFixed(2)}GB/${(memory.virtual.total / 1024 / 1024 / 1024).toFixed(2)}GB`;
70+
displaysInfo.value = displays.map(d => `${d.resolution.width}x${d.resolution.height}@${d.refreshRate}Hz`).join(', ');
71+
try {
72+
const imageversion = await filesystem.readFile('/etc/icpcimage-version')
73+
imageVer.value = imageversion;
74+
} catch (e) {
75+
imageVer.value = 'Unknown';
76+
}
77+
gccVer.value = await getVer('gcc --version', '[0-9.]+\.[0-9.]+(\.[0-9]+)?([_-p][0-9]+)?');
78+
gppVer.value = await getVer('g++ --version', '[0-9.]+\.[0-9.]+(\.[0-9]+)?([_-p][0-9]+)?');
79+
javaVer.value = await getVer('java -version', '[0-9.]+\.[0-9.]+(\.[0-9]+)?');
80+
kotlinVer.value = await getVer('kotlin -version', '[0-9.]+\.[0-9.]+(\.[0-9]+)?');
81+
python3Ver.value = await getVer('python3 --version', '[0-9.]+\.[0-9.]+(\.[0-9]+)?');
82+
pypy3Ver.value = await getVer('pypy3 --version', '[0-9.]+\.[0-9.]+(\.[0-9]+)?');
83+
});
84+
</script>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<template>
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" label="摄像头">
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>
20+
<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" label="桌面">
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>
40+
<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>
45+
</n-card>
46+
</template>
47+
48+
<script setup lang="ts">
49+
import { filesystem } from '@neutralinojs/lib';
50+
import { NCard, NGrid, NGi, NButton, NInput, NTabs, NTabPane } from 'naive-ui';
51+
import { onMounted, ref } from 'vue';
52+
53+
const cameraInfo = ref('');
54+
const screenInfo = ref('');
55+
// const betterCameraInfo = ref({});
56+
// const betterScreenInfo = ref({});
57+
58+
59+
onMounted(async () => {
60+
try {
61+
const camera = await filesystem.readFile('/etc/default/vlc-webcam');
62+
const screen = await filesystem.readFile('/etc/default/vlc-screen');
63+
cameraInfo.value = camera;
64+
screenInfo.value = screen;
65+
} catch (error) {
66+
console.error(error);
67+
cameraInfo.value = 'no camera config found';
68+
screenInfo.value = 'no screen config found';
69+
}
70+
});
71+
</script>

0 commit comments

Comments
 (0)