feat(integrations,classisland,server,web,desktop): ClassIsland 联动插件——上报课表与上课状态、下发提醒并回执、教室端推送通道
教室机器上的 ClassIsland 现在可以直接和班级小助手互通:插件走 /api/integrations/classisland/*,用设备令牌(X-ClassIsland-Token,库里只存 sha256)独立鉴权,不占用 JWT 通道。 - 服务端:新增 integrations 模块(上报 / 待弹出 / 回执 / 课表镜像 / 回写),两个迁移(设备令牌表、Class.notificationChannel);通知、叫人、联动页下发统一复用 pushToClassIsland,避免"某个页面发的通知不联动" - 插件:packages/classisland-plugin(.NET 8,独立于 pnpm workspace)——BridgeService 上报与提醒轮询、ScheduleMapper/ClassPlanWriter 课表镜像、Avalonia 设置页、ClassHelperNotificationProvider 在 ClassIsland 上弹出提醒;本地/内网地址强制直连,躲开系统代理返回的假 404 - 客户端:设置页可选提醒通道(both / client / classisland),并订阅相应实时事件 - Web 端:新增「ClassIsland 联动」页(设备管理与提醒下发) - 校验与打包:verify:classisland(需后端)、verify:classisland-plugin(静态契约 54 项)、build/dist:classisland-plugin 产出 .cipx - 文档:README 与 AGENTS.md 同步新增联动说明,docs/screenshots/classisland 留三张真机截图 门禁:pnpm lint 0 error、pnpm typecheck 四包通过、verify:classisland-plugin 54/54 通过。运行期仍需在装了 ClassIsland 的机器上实测(步骤见 AGENTS.md §8)。
This commit is contained in:
1 parent
fe41ebb7d6
commit
d0830f6830
61 files changed
+7026
-93
No files matched your search
@@ -1,7 +1,14 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { app, safeStorage } from 'electron';
|
||||
import { DEFAULT_ISLAND_APPEARANCE, DEFAULT_SERVER_URL, type IslandAppearance } from '@classhelper/shared';
|
||||
import {
|
||||
CLASSISLAND_NOTIFICATION_CHANNELS,
|
||||
DEFAULT_CLASSISLAND_NOTIFICATION_CHANNEL,
|
||||
DEFAULT_ISLAND_APPEARANCE,
|
||||
DEFAULT_SERVER_URL,
|
||||
type ClassIslandNotificationChannel,
|
||||
type IslandAppearance,
|
||||
} from '@classhelper/shared';
|
||||
import type { DesktopStoredConfig, HomeworkBoardSettings } from '../types/desktop.js';
|
||||
|
||||
/** 作业页展示偏好默认值(看板 + 不显示时间 + 15px) */
|
||||
@@ -22,6 +29,8 @@ interface PersistedConfig {
|
||||
island?: Partial<IslandAppearance>;
|
||||
/** 作业页展示偏好(向后兼容:旧配置文件没有该字段时用默认值补齐) */
|
||||
homeworkBoard?: Partial<HomeworkBoardSettings>;
|
||||
/** 通知显示位置(向后兼容:旧配置文件没有该字段时按默认 both 补齐) */
|
||||
notificationChannel?: ClassIslandNotificationChannel;
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: PersistedConfig = {
|
||||
@@ -31,8 +40,18 @@ const DEFAULT_CONFIG: PersistedConfig = {
|
||||
tokenEncrypted: false,
|
||||
island: { ...DEFAULT_ISLAND_APPEARANCE },
|
||||
homeworkBoard: { ...DEFAULT_HOMEWORK_BOARD },
|
||||
notificationChannel: DEFAULT_CLASSISLAND_NOTIFICATION_CHANNEL,
|
||||
};
|
||||
|
||||
/** 通知显示位置的白名单校验:非法值一律回落到默认值,避免坏配置把提醒"静默吞掉" */
|
||||
function normalizeNotificationChannel(
|
||||
input?: ClassIslandNotificationChannel,
|
||||
): ClassIslandNotificationChannel {
|
||||
return CLASSISLAND_NOTIFICATION_CHANNELS.includes(input as ClassIslandNotificationChannel)
|
||||
? (input as ClassIslandNotificationChannel)
|
||||
: DEFAULT_CLASSISLAND_NOTIFICATION_CHANNEL;
|
||||
}
|
||||
|
||||
/** 作业页偏好的合法化(模式白名单、字号夹紧) */
|
||||
function normalizeHomeworkBoard(input?: Partial<HomeworkBoardSettings>): HomeworkBoardSettings {
|
||||
const mode = input?.mode === 'list' ? 'list' : 'board';
|
||||
@@ -126,6 +145,7 @@ function readPersisted(): PersistedConfig {
|
||||
tokenEncrypted: parsed.tokenEncrypted === true,
|
||||
island: normalizeIslandAppearance(parsed.island),
|
||||
homeworkBoard: normalizeHomeworkBoard(parsed.homeworkBoard),
|
||||
notificationChannel: normalizeNotificationChannel(parsed.notificationChannel),
|
||||
};
|
||||
} catch {
|
||||
return { ...DEFAULT_CONFIG };
|
||||
@@ -147,6 +167,7 @@ export function getConfig(): DesktopStoredConfig {
|
||||
token: decryptToken(persisted),
|
||||
island: normalizeIslandAppearance(persisted.island),
|
||||
homeworkBoard: normalizeHomeworkBoard(persisted.homeworkBoard),
|
||||
notificationChannel: normalizeNotificationChannel(persisted.notificationChannel),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -169,6 +190,9 @@ export function saveConfig(patch: Partial<DesktopStoredConfig>): DesktopStoredCo
|
||||
...patch.homeworkBoard,
|
||||
});
|
||||
}
|
||||
if (patch.notificationChannel !== undefined) {
|
||||
persisted.notificationChannel = normalizeNotificationChannel(patch.notificationChannel);
|
||||
}
|
||||
if (patch.token !== undefined) {
|
||||
const encrypted = encryptToken(patch.token);
|
||||
persisted.token = encrypted.token;
|
||||
|
||||
@@ -2536,6 +2536,69 @@ async function runSettingsPageAppearanceCheck(
|
||||
return { ok: false, detail: result?.detail ?? '未执行' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置页「通知显示位置」自检(需求:提醒弹在 ClassHelper 还是 ClassIsland,由客户端自己选)。
|
||||
*
|
||||
* 走真实 UI:切到设置页 → 点单选项 → 断言「本地配置已写入」,再切回去。
|
||||
* 服务端同步(写回班级记录)由 verify:classisland 覆盖,这里只管客户端这一半。
|
||||
*/
|
||||
async function runSettingsPageChannelCheck(
|
||||
win: BrowserWindow,
|
||||
): Promise<{ ok: boolean; detail: string }> {
|
||||
const result = (await win.webContents
|
||||
.executeJavaScript(
|
||||
`(async () => {
|
||||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const before = (await window.desktop.getConfig()).notificationChannel;
|
||||
location.hash = '#/settings';
|
||||
|
||||
// 找到「通知显示位置」那张卡片里的单选组
|
||||
let group = null;
|
||||
for (let i = 0; i < 40 && !group; i += 1) {
|
||||
await wait(100);
|
||||
group = Array.from(document.querySelectorAll('.el-card')).find((card) =>
|
||||
(card.querySelector('.el-card__header')?.textContent ?? '').includes('通知显示位置'),
|
||||
);
|
||||
}
|
||||
if (!group) return { ok: false, detail: '设置页没有「通知显示位置」卡片' };
|
||||
const radios = Array.from(group.querySelectorAll('.el-radio'));
|
||||
// 注意:这段脚本本身是外层模板字符串,里面不能再出现反引号(会截断外层字符串)
|
||||
if (radios.length < 3) return { ok: false, detail: '单选项只有 ' + radios.length + ' 个' };
|
||||
|
||||
// 点第二个(只在 ClassHelper 客户端弹),断言配置真的写下去了
|
||||
radios[1].click();
|
||||
await wait(600);
|
||||
const afterClient = (await window.desktop.getConfig()).notificationChannel;
|
||||
const clientChecked = radios[1].classList.contains('is-checked');
|
||||
|
||||
// 再点回第一个(两端都弹),避免影响后续用例
|
||||
radios[0].click();
|
||||
await wait(600);
|
||||
const afterBoth = (await window.desktop.getConfig()).notificationChannel;
|
||||
|
||||
location.hash = '#/schedule';
|
||||
return { ok: true, before, afterClient, afterBoth, clientChecked, labels: radios.map((n) => n.textContent.trim()) };
|
||||
})()`,
|
||||
)
|
||||
.catch((error: unknown) => ({
|
||||
ok: false as const,
|
||||
detail: `执行失败:${error instanceof Error ? error.message : String(error)}`,
|
||||
}))) as
|
||||
| { ok: true; before: string; afterClient: string; afterBoth: string; clientChecked: boolean; labels: string[] }
|
||||
| { ok: false; detail: string }
|
||||
| null;
|
||||
|
||||
if (result?.ok) {
|
||||
return {
|
||||
ok: result.afterClient === 'client' && result.clientChecked && result.afterBoth === 'both',
|
||||
detail:
|
||||
`单选项=[${result.labels.join(' / ')}],` +
|
||||
`选择「只在 ClassHelper 客户端弹」后配置 ${result.before} → ${result.afterClient}(选中=${result.clientChecked}),` +
|
||||
`切回后 ${result.afterBoth}`,
|
||||
};
|
||||
}
|
||||
return { ok: false, detail: result?.detail ?? '未执行' };
|
||||
}
|
||||
/**
|
||||
* Electron 冒烟验证(ELECTRON_SMOKE_TEST=1 时触发,跑完自动退出)。
|
||||
* 覆盖:preload 桥接、渲染进程挂载、登录页 DOM、IndexedDB 缓存读写、离线回退,
|
||||
@@ -2732,6 +2795,10 @@ export async function runSmokeTest(win: BrowserWindow): Promise<void> {
|
||||
const settingsAppearance = await runSettingsPageAppearanceCheck(win);
|
||||
record('设置页真实 UI:拖拽滑块即时改变灵动岛外观', settingsAppearance.ok, settingsAppearance.detail);
|
||||
|
||||
// 通知显示位置(客户端自己选):提醒弹在 ClassHelper 还是 ClassIsland
|
||||
const settingsChannel = await runSettingsPageChannelCheck(win);
|
||||
record('设置页真实 UI:切换「通知显示位置」写回本地配置', settingsChannel.ok, settingsChannel.detail);
|
||||
|
||||
// 真实通知链路:教师发通知 → 客户端实时通道 → 灵动岛胶囊;
|
||||
// 随后在灵动岛点"标为已读",验证通知中心同步为已读(修复"点了已读仍显示未读")
|
||||
const realtime = await runIslandRealtimeCheck(win);
|
||||
|
||||
Reference in new issue
Block a user