Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SSmJaE committed Apr 19, 2021
1 parent 9c84790 commit cf0d894
Show file tree
Hide file tree
Showing 20 changed files with 690 additions and 122 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,26 @@
- 如果您开始使用本项目,即视为同意项目免责声明中的一切条款,条款更新不再另行通知。
- 如有触及相关平台规定或者权益,烦请联系我们删除。

## 已知问题
- 因为文件锁的原因,登录之后需要重启一下应用,才能同步cookie,下个版本修复

## 使用
### 登录
- 可以账号密码登录,也可以直接提供cookie
- 如果账号密码登录,登录成功之后,会自动同步cookie,不需要再操作
- 如果直接提供cookie,需要先验证cookie有效性,验证成功后,点击替换cookie即可
- 长期使用之后,可能会在某次登录后提示cookie失效,重复上述两步即可
- 尚未实现过期后自动使用账号密码重新获取cookie

### 活动
- 获取课程之后,可以添加至队列,也可以手动进行签到

### 签到任务设置
- 一门课程建议只配置一个任务,但是可以为该任务配置多个上课时间
- 选择合适的上课周期(最好和实际学期一致,或者和该门课的周期一致)和上课时间(比如可以比实际上课时间提前半小时),小工具会根据任务的周期和时间,自动优化整合时间范围,保证监控的效率和精确
- 建议选择较大的监控频率(至少60s),不然会被屏蔽,而获取不到活动信息

### 签到队列
- 添加、编辑、修改队列之后,是即时生效的,不需要重启

### 日志
- 可以筛选日志等级
- 可以控制是否自动下滑
11 changes: 11 additions & 0 deletions docs/pictures/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 2021-04-19 `v0.1.0`
- 第一版

## 2021-04-20 `v0.1.1`
### 修复与改进
- 通过仅由renderer进程访问lowdb,绕过文件锁,修复cookie不同步的问题
- 获取活动时,增加提示

### 新增
- 基于intro.js,实现使用教程
- 日志增加“当前活跃课程”
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xue-xi-tong-sign-electron",
"productName": "xue-xi-tong-sign-electron",
"productName": "签到小工具",
"version": "1.0.0",
"description": "A XueXiTong Sign Application, powered by Electron",
"main": ".webpack/main/index",
Expand Down Expand Up @@ -76,6 +76,7 @@
"@electron-forge/plugin-webpack": "6.0.0-beta.54",
"@marshallofsound/webpack-asset-relocator-loader": "^0.5.0",
"@types/electron-devtools-installer": "^2.2.0",
"@types/intro.js": "^3.0.1",
"@types/lodash": "^4.14.168",
"@types/lowdb": "^1.0.9",
"@types/query-string": "^6.3.0",
Expand Down Expand Up @@ -106,6 +107,7 @@
"dayjs": "^1.10.4",
"electron-squirrel-startup": "^1.0.0",
"element-ui": "^2.15.1",
"intro.js": "^3.4.0",
"lodash": "^4.17.21",
"lowdb": "^1.0.0",
"query-string": "^7.0.0",
Expand All @@ -118,4 +120,4 @@
"vuex": "^3.6.2",
"vuex-module-decorators": "^1.0.1"
}
}
}
25 changes: 6 additions & 19 deletions src/main/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,8 @@ import queryString from "query-string";
import axiosCookieJarSupport from "axios-cookiejar-support";
import tough from "tough-cookie";

// 和renderer公用一个db,会出现数据未同步的问题,不知道为什么
import low from "lowdb";
import FileSync from "lowdb/adapters/FileSync";

const adapter = new FileSync<IDataBase>("db.json");
const db = low(adapter);

axiosCookieJarSupport(axios);

function getCookie() {
return db
.get("user")
.get("cookie")
.value();
}

const cookieJar = new tough.CookieJar();

function generateUserAgent(platform: "desktop" | "mobile") {}
Expand Down Expand Up @@ -95,10 +81,10 @@ export async function isCookieValid(cookie: string) {
}
}

export async function getCourses(): Promise<string> {
export async function getCourses(cookie: string): Promise<string> {
return await axios.get("https://mooc2-ans.chaoxing.com/visit/courses/list", {
headers: {
Cookie: getCookie(),
Cookie: cookie,
"User-Agent": PC_AGENT,
},
params: {
Expand All @@ -111,13 +97,14 @@ export async function getCourses(): Promise<string> {
}

export async function getActivities({
cookie,
courseId,
classId,
uid,
}: IGetActivities): Promise<IGetActivitiesReturn> {
return await axios.get(`https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist`, {
headers: {
Cookie: getCookie(),
Cookie: cookie,
"User-Agent":
"Dalvik/2.1.0 (Linux; U; Android 10; MI 8 MIUI/V12.0.3.0.QEACNXM) com.chaoxing.mobile/ChaoXingStudy_3_4.7.4_android_phone_593_53 (@Kalimdor)_df14728a529c4e608a7b8f1112ca2825",
},
Expand All @@ -129,10 +116,10 @@ export async function getActivities({
});
}

export async function sign({ activeId, uid }: ISign): Promise<string> {
export async function sign({ cookie, activeId, uid }: ISign): Promise<string> {
return await axios.get("https://mobilelearn.chaoxing.com/pptSign/stuSignajax", {
headers: {
Cookie: getCookie(),
Cookie: cookie,
"User-Agent":
"Dalvik/2.1.0 (Linux; U; Android 10; MI 8 MIUI/V12.0.3.0.QEACNXM) com.chaoxing.mobile/ChaoXingStudy_3_4.7.4_android_phone_593_53 (@Kalimdor)_df14728a529c4e608a7b8f1112ca2825",
},
Expand Down
52 changes: 49 additions & 3 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Component } from "vue-property-decorator";
import { mixins } from "vue-class-component";
import { WithLogNotify } from "./mixins/common";
Expand Down Expand Up @@ -71,6 +71,10 @@ export default class App extends mixins(WithLogNotify) {
logger.success(`normal类型签到成功`);
new Notification("签到小工具", {
body: `${task.courseName}签到成功`,
});
taskModule.saveSigned(activity.id);
});
Expand Down Expand Up @@ -101,6 +105,8 @@ export default class App extends mixins(WithLogNotify) {
this.startHeartBeat();
logger.success("初始化成功");
// this.intro();
}
async startHeartBeat() {
Expand All @@ -114,8 +120,13 @@ export default class App extends mixins(WithLogNotify) {
// 获取unix
const current = Math.floor(Date.now() / 1000);
if (current - lastHeartBeatTime > 9.5) {
logger.debug("心跳 in heartBeart");
if (lastHeartBeatTime === 0 || current - lastHeartBeatTime > 60) {
logger.debug("检测当前活跃任务");
this.refreshActiveTasks();
}
if (lastHeartBeatTime === 0 || current - lastHeartBeatTime > 9.5) {
logger.debug("任务队列心跳");
lastHeartBeatTime = current;
}
Expand Down Expand Up @@ -181,6 +192,16 @@ export default class App extends mixins(WithLogNotify) {
(activity) => !signedActivities.includes(activity.id)
);
if (newActivities.length) {
this.withLogNotify({
level: "success",
title: "有新签到",
message: `检测到${task.courseName}的新签到活动`,
});
} else {
logger.info(`${task.courseName}无新签到`);
}
for (const activity of newActivities) {
// 如果有新活动,判断活动类型,emit
// const activityType = this.figureSignType(activity);
Expand All @@ -189,5 +210,30 @@ export default class App extends mixins(WithLogNotify) {
watcher.emit("normal", task, activity);
}
}
refreshActiveTasks() {
const buffer: string[] = [];
const current = Math.floor(Date.now() / 1000);
for (const [taskId, { UTC }] of ObjectEntries(taskModule.parsedUTC)) {
if (UTC) {
for (const [start, end] of UTC) {
if (start <= current && current <= end) {
const currentCourseName = db
.get("tasks")
.find({ id: taskId })
.get("courseName")
.value();
buffer.push(currentCourseName);
}
}
}
}
taskModule.refreshActiveTasks(buffer);
logger.debug(`当前活跃任务 ${buffer.length ? buffer.join("") : ""}`);
}
}
</script>
3 changes: 3 additions & 0 deletions src/renderer/EventBus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Vue from "vue";

export default new Vue();
Loading

0 comments on commit cf0d894

Please sign in to comment.