mirror of
https://github.com/mousebomb/obsidian-diary-ics.git
synced 2026-07-22 05:49:47 +00:00
仅在端口变化点击应用后重启服务器,修改其他参数不再频繁重启
This commit is contained in:
parent
88d8a85321
commit
0cae534889
5 changed files with 28 additions and 16 deletions
4
LICENSE
4
LICENSE
|
|
@ -1,5 +1,5 @@
|
|||
Copyright (C) 2025-2025 by Mousebomb.
|
||||
Copyright (C) 2025-2025 by Mousebomb <mousebomb@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
|
|
|||
6
lang.ts
6
lang.ts
|
|
@ -21,6 +21,8 @@ interface LanguageStrings {
|
|||
settingsTitle: string;
|
||||
portSetting: string;
|
||||
portDesc: string;
|
||||
applyButton: string;
|
||||
portApplied: string;
|
||||
contentSettingsTitle: string;
|
||||
headingLevelSetting: string;
|
||||
headingLevelDesc: string;
|
||||
|
|
@ -74,6 +76,8 @@ const en: LanguageStrings = {
|
|||
settingsTitle: "Diary ICS Settings",
|
||||
portSetting: "HTTP Server Port",
|
||||
portDesc: "Port used by the local HTTP server",
|
||||
applyButton: "Apply",
|
||||
portApplied: "Port applied, server restarted",
|
||||
contentSettingsTitle: "Content Settings",
|
||||
headingLevelSetting: "Heading Level",
|
||||
headingLevelDesc: "Which level of headings to extract from diary as calendar entries",
|
||||
|
|
@ -127,6 +131,8 @@ const zh: LanguageStrings = {
|
|||
settingsTitle: "日记日历订阅设置",
|
||||
portSetting: "HTTP服务器端口",
|
||||
portDesc: "本地HTTP服务器使用的端口号",
|
||||
applyButton: "应用",
|
||||
portApplied: "端口已应用,服务器已重启",
|
||||
contentSettingsTitle: "内容设置",
|
||||
headingLevelSetting: "标题级别",
|
||||
headingLevelDesc: "从日记中提取哪一级标题作为日历条目",
|
||||
|
|
|
|||
30
main.ts
30
main.ts
|
|
@ -107,15 +107,15 @@ export default class DiaryIcsPlugin extends Plugin {
|
|||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
async saveSettings(restartServer = false) {
|
||||
await this.saveData(this.settings);
|
||||
|
||||
// 重启服务器以应用新设置
|
||||
if (this.server) {
|
||||
// 只有在需要时才重启服务器
|
||||
if (restartServer && this.server) {
|
||||
this.server.close();
|
||||
this.server = null;
|
||||
this.startServer();
|
||||
}
|
||||
this.startServer();
|
||||
}
|
||||
|
||||
// 启动HTTP服务器提供ICS文件
|
||||
|
|
@ -418,8 +418,14 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
const port = parseInt(value);
|
||||
if (!isNaN(port) && port > 0 && port < 65536) {
|
||||
this.plugin.settings.port = port;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false); // 不重启服务器
|
||||
}
|
||||
}))
|
||||
.addButton(button => button
|
||||
.setButtonText(locale.applyButton)
|
||||
.onClick(async () => {
|
||||
await this.plugin.saveSettings(true); // 重启服务器
|
||||
new Notice(locale.portApplied);
|
||||
}));
|
||||
|
||||
containerEl.createEl('h3', {text: locale.contentSettingsTitle});
|
||||
|
|
@ -433,7 +439,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.setValue(this.plugin.settings.headingLevel)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.headingLevel = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -443,7 +449,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.setValue(this.plugin.settings.includeSubheadings)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.includeSubheadings = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
// new Setting(containerEl)
|
||||
|
|
@ -467,7 +473,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.diaryFormat = value;
|
||||
this.plugin.dailyNoteFormat = value; // 立即更新插件实例中的值
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -479,7 +485,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.diaryFolder = value;
|
||||
this.plugin.dailyNoteFolder = value; // 立即更新插件实例中的值
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
containerEl.createEl('h3', {text: locale.frontmatterSettingsTitle});
|
||||
|
|
@ -491,7 +497,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.setValue(this.plugin.settings.includeFrontmatter)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.includeFrontmatter = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -502,7 +508,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.setValue(this.plugin.settings.frontmatterTitleTemplate)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.frontmatterTitleTemplate = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -513,7 +519,7 @@ class DiaryIcsSettingTab extends PluginSettingTab {
|
|||
.setValue(this.plugin.settings.frontmatterTemplate)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.frontmatterTemplate = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(false);
|
||||
}));
|
||||
|
||||
const templateExample = containerEl.createEl('div', {text: locale.templateExampleTitle});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "diary-ics",
|
||||
"name": "Diary ICS",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Sync Obsidian diary entries to system calendar via ICS feed.",
|
||||
"author": "Mousebomb",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-diary-ics",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.6",
|
||||
"description": "Sync Obsidian diary entries to system calendar via ICS feed.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue