mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-07-02 17:29:23 +00:00
添加通知权限和持久性存储请求功能,更新设置项默认值及描述
This commit is contained in:
parent
31497b26cd
commit
127347d76a
@ -1,3 +1,41 @@
|
|||||||
|
// 请求通知权限
|
||||||
|
async function requestNotificationPermission() {
|
||||||
|
if (Notification && Notification.requestPermission) {
|
||||||
|
const permission = await Notification.requestPermission();
|
||||||
|
if (permission === "granted") {
|
||||||
|
console.log("通知权限已授予");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.warn("通知权限被拒绝");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn("浏览器不支持通知权限请求");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 请求持久性存储权限
|
||||||
|
async function requestPersistentStorage() {
|
||||||
|
if (navigator.storage && navigator.storage.persist) {
|
||||||
|
const isPersisted = await navigator.storage.persist();
|
||||||
|
if (isPersisted) {
|
||||||
|
console.log("持久性存储已启用");
|
||||||
|
} else {
|
||||||
|
console.warn("持久性存储请求被拒绝");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn("浏览器不支持持久性存储");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在页面加载时请求通知权限和持久性存储
|
||||||
|
window.addEventListener("load", async () => {
|
||||||
|
const notificationGranted = await requestNotificationPermission();
|
||||||
|
if (notificationGranted) {
|
||||||
|
await requestPersistentStorage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置项定义
|
* 配置项定义
|
||||||
* @typedef {Object} SettingDefinition
|
* @typedef {Object} SettingDefinition
|
||||||
@ -20,7 +58,7 @@ const settingsDefinitions = {
|
|||||||
// 显示设置
|
// 显示设置
|
||||||
"display.emptySubjectDisplay": {
|
"display.emptySubjectDisplay": {
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "button", // 修改默认值为 'button'
|
default: "card", // 修改默认值为 'button'
|
||||||
validate: (value) => ["card", "button"].includes(value),
|
validate: (value) => ["card", "button"].includes(value),
|
||||||
description: "空科目的显示方式:卡片或按钮",
|
description: "空科目的显示方式:卡片或按钮",
|
||||||
},
|
},
|
||||||
@ -83,7 +121,8 @@ const settingsDefinitions = {
|
|||||||
default: true,
|
default: true,
|
||||||
description: "是否启用自动保存",
|
description: "是否启用自动保存",
|
||||||
},
|
},
|
||||||
"edit.blockNonTodayAutoSave": { // 添加新选项
|
"edit.blockNonTodayAutoSave": {
|
||||||
|
// 添加新选项
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: true,
|
default: true,
|
||||||
description: "禁止自动保存非当天数据",
|
description: "禁止自动保存非当天数据",
|
||||||
@ -93,7 +132,8 @@ const settingsDefinitions = {
|
|||||||
default: true,
|
default: true,
|
||||||
description: "编辑前是否自动刷新",
|
description: "编辑前是否自动刷新",
|
||||||
},
|
},
|
||||||
"edit.confirmNonTodaySave": { // 添加新选项
|
"edit.confirmNonTodaySave": {
|
||||||
|
// 添加新选项
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: true,
|
default: true,
|
||||||
description: "保存非当天数据时显示确认对话框,禁用则允许直接保存",
|
description: "保存非当天数据时显示确认对话框,禁用则允许直接保存",
|
||||||
@ -110,7 +150,8 @@ const settingsDefinitions = {
|
|||||||
default: false,
|
default: false,
|
||||||
description: "是否显示调试配置",
|
description: "是否显示调试配置",
|
||||||
},
|
},
|
||||||
"developer.disableMessageLog": { // 添加新的设置项
|
"developer.disableMessageLog": {
|
||||||
|
// 添加新的设置项
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: false,
|
default: false,
|
||||||
description: "禁用消息日志记录",
|
description: "禁用消息日志记录",
|
||||||
@ -244,7 +285,7 @@ function getSetting(key) {
|
|||||||
|
|
||||||
// 确保开发者相关设置正确处理
|
// 确保开发者相关设置正确处理
|
||||||
if (definition.requireDeveloper) {
|
if (definition.requireDeveloper) {
|
||||||
const devEnabled = settingsCache['developer.enabled'];
|
const devEnabled = settingsCache["developer.enabled"];
|
||||||
if (!devEnabled) {
|
if (!devEnabled) {
|
||||||
return definition.default;
|
return definition.default;
|
||||||
}
|
}
|
||||||
@ -262,14 +303,14 @@ function logSettingsChange(key, oldValue, newValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const shouldLog =
|
const shouldLog =
|
||||||
settingsCache['developer.enabled'] &&
|
settingsCache["developer.enabled"] &&
|
||||||
settingsCache['developer.showDebugConfig'];
|
settingsCache["developer.showDebugConfig"];
|
||||||
|
|
||||||
if (shouldLog) {
|
if (shouldLog) {
|
||||||
console.log(`[Settings] ${key}:`, {
|
console.log(`[Settings] ${key}:`, {
|
||||||
old: oldValue,
|
old: oldValue,
|
||||||
new: newValue,
|
new: newValue,
|
||||||
time: new Date().toLocaleTimeString()
|
time: new Date().toLocaleTimeString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user