Skip to content

Commit 5e1ee09

Browse files
committed
完成bug修复
1 parent f360969 commit 5e1ee09

File tree

10 files changed

+190
-329
lines changed

10 files changed

+190
-329
lines changed

app/Language/modules/more_settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
"contributor_role_5": "创意、维护",
253253
"contributor_role_6": "应用测试、文档、安装包制作",
254254
"contributor_role_7": "响应式前端页面\n设计及维护、文档",
255+
"contributor_role_10": "ClassIsland 插件\nClassIsland 联动",
255256
},
256257
"donation": {"name": "捐赠支持", "description": "支持项目发展,感谢您的捐赠"},
257258
"website": {"name": "SecRandom 官网", "description": "访问SecRandom软件官网"},
@@ -275,6 +276,7 @@
275276
"contributor_role_5": "Creativity & Maintenance",
276277
"contributor_role_6": "Test & Documentation & Install Package Making",
277278
"contributor_role_7": "Responsive frontend page Design and Maintenance & Documentation",
279+
"contributor_role_10": "Test & Documentation & Install Package Making",
278280
},
279281
"donation": {"name": "Donate", "description": "Buy me a coffee"},
280282
"check_update": {

app/common/IPC_URL/csharp_ipc_handler.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(self):
6767
self.is_running = False
6868
self.is_connected = False
6969
self._disconnect_logged = False # 跟踪是否已记录断连日志
70+
self._last_on_class_left_log_time = 0 # 上次记录距离上课时间的时间
7071

7172
def start_ipc_client(self) -> bool:
7273
"""
@@ -141,6 +142,43 @@ def is_breaking(self) -> bool:
141142
)
142143
return state
143144

145+
def get_on_class_left_time(self) -> int:
146+
"""获取距离上课剩余时间(秒)
147+
148+
Returns:
149+
int: 距离上课的剩余时间(秒),如果当前正在上课或没有下一节课程则返回0
150+
"""
151+
try:
152+
import time
153+
154+
lessonSc = GeneratedIpcFactory.CreateIpcProxy[IPublicLessonsService](
155+
self.ipc_client.Provider, self.ipc_client.PeerProxy
156+
)
157+
on_class_left_time = lessonSc.OnClassLeftTime
158+
total_seconds = int(on_class_left_time.TotalSeconds)
159+
160+
# 根据距离上课的时间调整日志记录频率
161+
# 距离上课3秒前:每30秒记录一次
162+
# 距离上课3秒内:每秒记录一次
163+
current_time = time.time()
164+
should_log = False
165+
166+
if total_seconds > 0 and total_seconds <= 3:
167+
# 3秒内,每秒记录一次
168+
should_log = True
169+
elif current_time - self._last_on_class_left_log_time >= 30:
170+
# 3秒前,每30秒记录一次
171+
should_log = True
172+
self._last_on_class_left_log_time = current_time
173+
174+
if should_log:
175+
logger.debug(f"获取到的距离上课剩余时间: {total_seconds} 秒")
176+
177+
return total_seconds
178+
except Exception as e:
179+
logger.error(f"获取距离上课时间失败: {e}")
180+
return 0
181+
144182
@staticmethod
145183
def convert_to_call_result(
146184
class_name: str, selected_students, draw_count: int, display_duration=5.0
@@ -270,6 +308,14 @@ def is_breaking(self) -> bool:
270308
"""是否处于下课时间"""
271309
return False
272310

311+
def get_on_class_left_time(self) -> int:
312+
"""获取距离上课剩余时间(秒)
313+
314+
Returns:
315+
int: 距离上课的剩余时间(秒),如果当前正在上课或没有下一节课程则返回0
316+
"""
317+
return 0
318+
273319
@staticmethod
274320
def convert_to_call_result(
275321
class_name: str, selected_students, draw_count: int, display_duration=5.0

app/common/IPC_URL/url_command_handler.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class URLCommandHandler(QObject):
2424
showMainPageRequested = Signal(str) # 请求显示主页面
2525
showTrayActionRequested = Signal(str) # 请求执行托盘操作
2626
securityVerificationRequested = Signal(str, dict) # 请求安全验证
27-
classIslandDataReceived = Signal(dict) # 接收ClassIsland数据信号
2827

2928
def __init__(self, main_window=None):
3029
super().__init__()
@@ -63,8 +62,6 @@ def __init__(self, main_window=None):
6362
"open": self._handle_open,
6463
"action": self._handle_action,
6564
"verify": self._handle_verify,
66-
# ClassIsland数据命令
67-
"data/class_island": self._handle_class_island_data,
6865
}
6966

7067
# 需要密码验证的命令列表
@@ -637,74 +634,6 @@ def _handle_verify(self, params: Dict[str, Any]) -> Dict[str, Any]:
637634
# 这里可以实现具体的验证逻辑
638635
return {"status": "success", "message": "验证通过", "verified": True}
639636

640-
def _handle_class_island_data(self, params: Dict[str, Any]) -> Dict[str, Any]:
641-
"""处理ClassIsland数据
642-
接收包含课程表信息的JSON数据
643-
644-
Args:
645-
params: 包含ClassIsland数据的参数字典
646-
预期包含以下字段:
647-
- data: ClassIsland发送的课程表数据
648-
- CurrentSubject: 当前所处时间点的科目
649-
- NextClassSubject: 下一节课的科目
650-
- CurrentState: 当前时间点状态
651-
- CurrentTimeLayoutItem: 当前所处的时间点
652-
- CurrentClassPlan: 当前加载的课表
653-
- NextBreakingTimeLayoutItem: 下一个课间休息类型的时间点
654-
- NextClassTimeLayoutItem: 下一个上课类型的时间点
655-
- CurrentSelectedIndex: 当前所处时间点的索引
656-
- OnClassLeftTime: 距离上课剩余时间
657-
- OnBreakingTimeLeftTime: 距下课剩余时间
658-
- IsClassPlanEnabled: 是否启用课表
659-
- IsClassPlanLoaded: 是否已加载课表
660-
- IsLessonConfirmed: 是否已确定当前时间点
661-
"""
662-
logger.debug("处理ClassIsland数据")
663-
664-
# 从参数中获取ClassIsland数据
665-
class_island_data = params.get("data", {})
666-
667-
if not class_island_data:
668-
logger.warning("收到空的ClassIsland数据")
669-
return {"status": "error", "message": "ClassIsland数据不能为空"}
670-
671-
# 验证必要的字段是否存在
672-
required_fields = [
673-
"CurrentSubject",
674-
"NextClassSubject",
675-
"CurrentState",
676-
"CurrentTimeLayoutItem",
677-
"CurrentClassPlan",
678-
"NextBreakingTimeLayoutItem",
679-
"NextClassTimeLayoutItem",
680-
"CurrentSelectedIndex",
681-
"OnClassLeftTime",
682-
"OnBreakingTimeLeftTime",
683-
"IsClassPlanEnabled",
684-
"IsClassPlanLoaded",
685-
"IsLessonConfirmed",
686-
]
687-
688-
for field in required_fields:
689-
if field not in class_island_data:
690-
logger.warning(f"ClassIsland数据缺少必要字段: {field}")
691-
692-
# 发射信号,让主窗口处理ClassIsland数据
693-
try:
694-
self.classIslandDataReceived.emit(class_island_data)
695-
logger.debug("ClassIsland数据已发送到主窗口处理")
696-
return {
697-
"status": "success",
698-
"message": "ClassIsland数据已接收并处理",
699-
"data_received": True,
700-
}
701-
except Exception as e:
702-
logger.error(f"发送ClassIsland数据信号失败: {e}")
703-
return {
704-
"status": "error",
705-
"message": f"发送ClassIsland数据信号失败: {str(e)}",
706-
}
707-
708637
def register_command(
709638
self,
710639
command: str,

app/common/extraction/extract.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,52 @@ def _get_class_times_by_day(day_of_week: int) -> Dict[str, str]:
192192
return parser.get_class_times_by_day(day_of_week)
193193

194194

195+
def _get_seconds_to_next_class() -> int:
196+
"""获取距离下一节课的剩余时间(秒)
197+
198+
Returns:
199+
int: 距离下一节课的剩余秒数,如果没有下一节课则返回0
200+
"""
201+
try:
202+
current_day_of_week = _get_current_day_of_week()
203+
class_times = _get_class_times_by_day(current_day_of_week)
204+
205+
if not class_times or not isinstance(class_times, dict):
206+
return 0
207+
208+
current_total_seconds = _get_current_time_in_seconds()
209+
210+
# 将上课时间段按开始时间排序
211+
time_ranges = []
212+
for range_name, time_range in class_times.items():
213+
try:
214+
start_end = time_range.split("-")
215+
if len(start_end) != 2:
216+
continue
217+
218+
start_time_str, end_time_str = start_end
219+
start_total_seconds = _parse_time_string_to_seconds(start_time_str)
220+
time_ranges.append((start_total_seconds, range_name))
221+
except Exception as e:
222+
logger.error(f"解析时间段失败: {range_name} = {time_range}, 错误: {e}")
223+
continue
224+
225+
# 按开始时间排序
226+
time_ranges.sort(key=lambda x: x[0])
227+
228+
# 找到下一个上课时间段
229+
for start_seconds, range_name in time_ranges:
230+
if start_seconds > current_total_seconds:
231+
return start_seconds - current_total_seconds
232+
233+
# 如果当天没有下一节课,返回0
234+
return 0
235+
236+
except Exception as e:
237+
logger.error(f"计算距离下一节课时间失败: {e}")
238+
return 0
239+
240+
195241
def _get_non_class_times_config() -> Dict[str, str]:
196242
"""获取非上课时间段配置
197243

app/page_building/settings_window_page.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ def __init__(self, parent: QFrame = None, is_preview=False):
159159

160160
if readme_settings_async("basic_settings", "simplified_mode"):
161161
page_config = {}
162-
if show_behind_scenes:
163-
page_config["behind_scenes_settings"] = get_content_name_async(
164-
"behind_scenes_settings", "title"
165-
)
166162
page_config["course_settings"] = get_content_name_async(
167163
"course_settings", "title"
168164
)

app/tools/settings_default_storage.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,7 @@
435435
"verification_required": {"default_value": True},
436436
"instant_draw_disable": {"default_value": False},
437437
"class_island_source_enabled": {"default_value": False},
438-
"current_class_island_break_status": {"default_value": False},
439-
"last_class_island_state": {"default_value": ""},
440-
"pre_class_reset_enabled": {"default_value": True},
438+
"pre_class_reset_enabled": {"default_value": False},
441439
"pre_class_reset_time": {"default_value": 120},
442440
},
443441
"fair_draw_settings": {

app/tools/url_handler.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ def __init__(self, app_name: str = "SecRandom", protocol_name: str = "secrandom"
4343
self.command_handler.showTrayActionRequested.connect(
4444
self.showTrayActionRequested.emit
4545
)
46-
# 连接ClassIsland数据信号
47-
self.command_handler.classIslandDataReceived.connect(
48-
self._handle_class_island_data
49-
)
5046

5147
def parse_command_line_args(self) -> Optional[Dict[str, Any]]:
5248
"""
@@ -172,10 +168,6 @@ def check_single_instance(self) -> bool:
172168
self.url_ipc_handler.register_message_handler(
173169
"url", self._handle_ipc_url_message
174170
)
175-
# 注册ClassIsland数据消息处理器
176-
self.url_ipc_handler.register_message_handler(
177-
"class_island_data", self._handle_ipc_class_island_message
178-
)
179171
return True
180172
else:
181173
return False
@@ -190,28 +182,6 @@ def _handle_ipc_url_message(self, payload: Dict[str, Any]) -> Dict[str, Any]:
190182
else:
191183
return {"success": False, "error": "缺少URL参数"}
192184

193-
def _handle_ipc_class_island_message(
194-
self, payload: Dict[str, Any]
195-
) -> Dict[str, Any]:
196-
"""
197-
处理IPC ClassIsland数据消息
198-
199-
Args:
200-
payload: 包含ClassIsland数据的负载
201-
202-
Returns:
203-
处理结果
204-
"""
205-
class_island_data = payload.get("data", {})
206-
if class_island_data:
207-
# 调用command_handler处理ClassIsland数据
208-
# 构建参数字典,包含ClassIsland数据
209-
params = {"data": class_island_data}
210-
# 使用command_handler的_class_island_data方法处理数据
211-
return self.command_handler._handle_class_island_data(params)
212-
else:
213-
return {"success": False, "error": "缺少ClassIsland数据参数"}
214-
215185
def send_url_to_existing_instance(self, url: str) -> bool:
216186
"""
217187
发送URL到已存在的实例
@@ -231,21 +201,6 @@ def send_url_to_existing_instance(self, url: str) -> bool:
231201
else:
232202
return False
233203

234-
def _handle_class_island_data(self, class_island_data: dict):
235-
"""
236-
处理ClassIsland数据
237-
238-
Args:
239-
class_island_data: ClassIsland发送的数据
240-
"""
241-
# 将ClassIsland数据信号转发给主窗口
242-
# 这里可以添加额外的处理逻辑
243-
logger.info("URLHandler接收到ClassIsland数据")
244-
245-
# 发射信号,让主窗口处理数据
246-
# 注意:URLHandler本身不直接处理UI逻辑,只是转发信号
247-
self.classIslandDataReceived.emit(class_island_data)
248-
249204

250205
def handle_url_arguments() -> Optional[Dict[str, Any]]:
251206
"""

app/view/another_window/contributor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ def _init_data(self):
112112
"github": "https://github.com/jursin",
113113
"avatar": str(get_data_path("assets/contribution", "contributor7.png")),
114114
},
115+
{
116+
"name": "lrs2187",
117+
"role": get_any_position_value_async(
118+
"about", "contributor", "contributor_role_10"
119+
),
120+
"github": "https://github.com/lrsgzs",
121+
"avatar": str(
122+
get_data_path("assets/contribution", "contributor10.png")
123+
),
124+
},
115125
{
116126
"name": "LHGS-github",
117127
"role": get_any_position_value_async(

0 commit comments

Comments
 (0)