Skip to content

Commit 28591c5

Browse files
authored
Merge pull request #6 from HEX9CF/dev
dev
2 parents 7ca3ba0 + c628949 commit 28591c5

File tree

12 files changed

+175
-114
lines changed

12 files changed

+175
-114
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ STU_PASSWORD=password
5555
AUTO_LOGIN=TRUE
5656
# 认证成功后自动退出程序
5757
AUTO_EXIT=FALSE
58+
# 启动程序后自动隐藏窗口
59+
AUTO_HIDE=FALSE
5860
5961
# 自动监控网络流量
6062
MONITOR_FLUX=TRUE
@@ -68,7 +70,9 @@ MONITOR_LOGOUT_THRESHOLD=10
6870

6971
## 开机自启
7072

71-
用户可以将程序添加到开机启动项,实现开机自动登录校园网。步骤如下:
73+
用户可以将程序添加到开机启动项,实现开机自动登录校园网。
74+
75+
这里以 Windows 系统为例,具体步骤如下:
7276

7377
1. 将可执行文件移动到一个固定的目录,如 `C:\Program Files\Cupid Connector`
7478
2. 右键点击可执行文件 `cupid-connector.exe`,选择“创建快捷方式”。

app.go

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import (
44
"context"
55
"cupid-connector/internal/conf"
66
"cupid-connector/internal/data"
7-
"cupid-connector/internal/service/login"
87
"cupid-connector/internal/ticker"
9-
"log"
10-
"os"
11-
"time"
12-
138
"github.com/go-toast/toast"
149
"github.com/wailsapp/wails/v2/pkg/runtime"
10+
"log"
1511
)
1612

1713
const AppID = "Cupid Connector"
@@ -35,54 +31,39 @@ func (a *App) startup(ctx context.Context) {
3531
log.Println(err)
3632
return
3733
}
34+
3835
// 刷新信息
3936
a.RefreshInfo()
40-
if data.Config.Basic.AutoLogin == "TRUE" {
41-
err = login.Login()
42-
if err != nil {
43-
log.Println(err)
44-
n := toast.Notification{
45-
AppID: AppID,
46-
Title: "校园网登录失败",
47-
Message: "错误信息:" + err.Error(),
48-
}
49-
err := n.Push()
50-
if err != nil {
51-
log.Fatalln(err)
52-
}
53-
} else {
54-
msg := "登录成功,用户:" + data.Config.Basic.Username + ",您已通过上网认证!"
55-
if data.Config.Basic.AutoExit == "TRUE" {
56-
msg += "程序将在3秒后自动退出"
57-
}
58-
n := toast.Notification{
59-
AppID: AppID,
60-
Title: "校园网登录成功",
61-
Message: msg,
62-
}
63-
err = n.Push()
64-
if err != nil {
65-
log.Fatalln(err)
66-
}
67-
// 刷新信息
68-
a.RefreshInfo()
69-
}
70-
if err == nil && data.Config.Basic.AutoExit == "TRUE" {
71-
time.Sleep(3 * time.Second)
72-
os.Exit(0)
73-
}
74-
}
37+
38+
// 自动登录
39+
a.autoLogin()
7540

7641
// 初始化定时器
7742
err = ticker.Set()
7843
if err != nil {
44+
log.Println(err)
7945
return
8046
}
8147

8248
// 启动监控
8349
go a.startMonitor()
8450

51+
// 自动隐藏窗口
8552
if data.Config.Basic.AutoHide == "TRUE" {
53+
log.Println("自动隐藏窗口")
54+
n := toast.Notification{
55+
AppID: AppID,
56+
Title: "Cupid Connector",
57+
Message: "窗口已最小化到托盘",
58+
}
59+
err = n.Push()
60+
if err != nil {
61+
log.Println(err)
62+
return
63+
}
8664
runtime.WindowHide(ctx)
8765
}
8866
}
67+
68+
func (a *App) shutdown(ctx context.Context) {
69+
}

frontend/src/components/Info.vue

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<div class="flux-chart">
4747
<div class="statistics-area-chart" ref="chartDom"></div>
4848
</div>
49-
<div class="surplus" v-if="info">
50-
剩余流量:{{ parseFloat((info.overall - info?.used).toFixed(3)) }}MB
49+
<div class="flux" v-if="info">
50+
已用流量: {{ info?.used }} MB / 流量总额: {{ info?.overall }} MB
5151
</div>
5252
</div>
5353
</template>
@@ -72,6 +72,7 @@ const isNoData = ref<boolean>(true)
7272
const getInfo = async () => {
7373
isLoading.value = true
7474
await GetInfo().then((res) => {
75+
console.log(res)
7576
if (res.code === 1) {
7677
info.value = res.data
7778
isNoData.value = false;
@@ -113,24 +114,24 @@ const updateOption = async () => {
113114
splitNumber: 8,
114115
type: 'gauge',
115116
itemStyle: {
116-
color: '#58D9F9',
117+
color: '#aaa',
117118
shadowColor: 'rgba(0,138,255,0.45)',
118119
shadowBlur: 10,
119120
shadowOffsetX: 2,
120121
shadowOffsetY: 2,
121122
},
122123
progress: {
123-
show: true,
124-
width: 18
124+
show: false,
125+
width: 18,
125126
},
126127
axisLine: {
127128
lineStyle: {
128129
width: 18,
129130
color: [
130-
[0.25, '#7CFFB2'],
131-
[0.5, '#58D9F9'],
132-
[0.75, '#FDDD60'],
133-
[1, '#FF6E76']
131+
[0.25, '#FF6E76'],
132+
[0.5, '#FDDD60'],
133+
[0.75, '#58D9F9'],
134+
[1, '#7CFFB2']
134135
]
135136
}
136137
},
@@ -164,13 +165,13 @@ const updateOption = async () => {
164165
valueAnimation: true,
165166
fontSize: 20,
166167
offsetCenter: [0, '85%'],
167-
formatter: '{value}' + 'MB',
168+
formatter: '{value}' + ' MB',
168169
color: '#fff'
169170
},
170171
data: [
171172
{
172-
value: info.value?.used,
173-
name: '已使用',
173+
value: parseFloat(((info.value?.overall ?? 0) - (info.value?.used ?? 0)).toFixed(2) ?? 0),
174+
name: '剩余流量',
174175
}
175176
]
176177
}
@@ -194,20 +195,25 @@ const updateInfo = async () => {
194195
myChart.value = echarts.init(chartDom.value);
195196
await updateOption();
196197
}
198+
isLoading.value = false
197199
}
198200
199201
onMounted(async () => {
200202
EventsOn("updateInfo", async () => {
201203
isLoading.value = true
202204
await updateInfo();
205+
isLoading.value = false
203206
})
207+
setTimeout(async () => {
208+
await updateInfo()
209+
}, 3000)
204210
})
205211
</script>
206212

207213
<style scoped>
208214
.statistics-area-chart {
209-
width: 240px;
210-
height: 240px;
215+
width: 220px;
216+
height: 210px;
211217
text-align: center;
212218
}
213219
@@ -216,4 +222,9 @@ onMounted(async () => {
216222
justify-content: center;
217223
text-align: center;
218224
}
225+
226+
.flux {
227+
font-size: 12px;
228+
color: #aaa;
229+
}
219230
</style>

frontend/src/components/Menu.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ import { SwitchButton, Minus } from "@element-plus/icons-vue";
33
import { Exit } from "../../wailsjs/go/main/App";
44
import { WindowHide } from "../../wailsjs/runtime/runtime";
55
6-
const handleClick = () => {
6+
const handleExit = () => {
77
Exit();
88
}
99
</script>
1010

1111
<template>
1212
<el-menu class="el-menu-demo" mode="horizontal" :ellipsis="false" text-color="#fff" active-text-color="#fff">
13-
<el-menu-item>
14-
<h1>Cupid Connector</h1>
15-
</el-menu-item>
13+
<div class="logo">
14+
<h3>
15+
Cupid Connector
16+
</h3>
17+
</div>
1618
<div class="button-container">
1719
<el-button class="minus-button" text :icon="Minus" @click="WindowHide"></el-button>
18-
<el-button class="exit-button" text :icon="SwitchButton" @click="handleClick"></el-button>
20+
<el-button class="exit-button" text :icon="SwitchButton" @click="handleExit"></el-button>
1921
</div>
2022
</el-menu>
2123
</template>
@@ -28,6 +30,11 @@ const handleClick = () => {
2830
margin-right: auto;
2931
}
3032
33+
.logo {
34+
margin-right: auto;
35+
color: #99ccff;
36+
}
37+
3138
.button-container {
3239
display: flex;
3340
align-items: center;

frontend/src/components/Setting.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-button type="primary" @click="handleClick" :icon="Setting" size="small">设置</el-button>
3-
<el-dialog v-model="dialogFormVisible" title="设置" width="400">
3+
<el-dialog v-model="dialogFormVisible" width="400">
44
<el-form :model="conf">
55
<el-form-item label="URL" required>
66
<el-input v-model="conf.base_url" placeholder="https://a.stu.edu.cn"></el-input>
@@ -11,13 +11,13 @@
1111
<el-form-item label="密码" required>
1212
<el-input v-model="conf.password" placeholder="password" type="password"></el-input>
1313
</el-form-item>
14-
<el-form-item label="启动程序自动登录">
14+
<el-form-item label="启动程序自动登录" class="form-btn">
1515
<el-switch v-model="auto_login"></el-switch>
1616
</el-form-item>
17-
<el-form-item label="认证成功自动退出">
17+
<el-form-item label="认证成功自动退出" class="form-btn">
1818
<el-switch v-model="auto_exit"></el-switch>
1919
</el-form-item>
20-
<el-form-item label="自动隐藏窗口">
20+
<el-form-item label="自动隐藏程序窗口" class="form-btn">
2121
<el-switch v-model="auto_hide"></el-switch>
2222
</el-form-item>
2323
</el-form>
@@ -72,4 +72,8 @@ const handleConfirm = async () => {
7272
});
7373
dialogFormVisible.value = false;
7474
};
75-
</script>
75+
</script>
76+
77+
<style>
78+
79+
</style>

internal/conf/create.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package conf
22

3-
import (
4-
"cupid-connector/internal/utils"
5-
"log"
6-
"os"
7-
)
8-
93
func CreateEnv() error {
104
setDefault()
115

@@ -16,36 +10,3 @@ func CreateEnv() error {
1610

1711
return nil
1812
}
19-
20-
func saveEnv() error {
21-
log.Println("正在创建配置文件...")
22-
v, err := utils.IsFileExists(envPath)
23-
if err != nil {
24-
log.Println("创建配置文件失败!")
25-
return err
26-
}
27-
if v {
28-
err := os.Remove(envPath)
29-
if err != nil {
30-
log.Println("删除旧配置文件失败!")
31-
return err
32-
}
33-
}
34-
file, err := os.Create(envPath)
35-
if err != nil {
36-
log.Println("创建配置文件失败!")
37-
return err
38-
}
39-
defer file.Close()
40-
41-
content := getEnvContent()
42-
43-
_, err = file.WriteString(content)
44-
if err != nil {
45-
log.Println("写入配置文件失败!")
46-
return err
47-
}
48-
49-
log.Println("创建配置文件成功!")
50-
return nil
51-
}

internal/conf/default.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package conf
33
import "cupid-connector/internal/data"
44

55
const (
6-
DefaultBaseUrl = "https://a.stu.edu.cn"
7-
DefaultUsername = ""
8-
DefaultPassword = ""
9-
DefaultAutoLogin = "TRUE"
10-
DefaultAutoExit = "FALSE"
6+
DefaultBaseUrl = "https://a.stu.edu.cn"
7+
DefaultUsername = ""
8+
DefaultPassword = ""
9+
10+
DefaultAutoLogin = "FALSE"
11+
DefaultAutoExit = "FALSE"
12+
DefaultAutoHide = "FALSE"
13+
1114
DefaultMonitorFlux = "FALSE"
1215
DefaultMonitorInterval = "5"
1316
DefaultAlertThreshold = "30"
1417
DefaultLogoutThreshold = "10"
15-
DefaultAutoHide = "FALSE"
1618
)
1719

1820
func setDefault() {
@@ -22,6 +24,7 @@ func setDefault() {
2224
data.Config.Basic.AutoLogin = DefaultAutoLogin
2325
data.Config.Basic.AutoExit = DefaultAutoExit
2426
data.Config.Basic.AutoHide = DefaultAutoHide
27+
2528
data.Config.Monitor.Enable = DefaultMonitorFlux
2629
data.Config.Monitor.Interval = DefaultMonitorInterval
2730
data.Config.Monitor.AlertThreshold = DefaultAlertThreshold

0 commit comments

Comments
 (0)