Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added download notifications #121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,20 @@ export default class ICSPlugin extends Plugin {
}

async getEvents(date: string): Promise<IEvent[]> {
if (
this.data.format.notificationLevel === 'light' ||
this.data.format.notificationLevel === 'verbose'
) {
new Notice('ICS: Downloading calendars...');
}

let events: IEvent[] = [];
let errorMessages: string[] = []; // To store error messages

for (const calendar in this.data.calendars) {
if (this.data.format.notificationLevel === 'verbose') {
new Notice(`ICS: Downloading '${calendar}'...`);
}
const calendarSetting = this.data.calendars[calendar];
let icsArray: any[] = [];

Expand Down Expand Up @@ -135,10 +145,17 @@ export default class ICSPlugin extends Plugin {

// Notify the user if any errors were encountered
if (errorMessages.length > 0) {
const message = `Encountered ${errorMessages.length} error(s) while processing calendars:\n\n${errorMessages.join('\n')}\nSee console for details.`;
const message = `ICS: Encountered ${errorMessages.length} error(s) while processing calendars:\n\n${errorMessages.join('\n')}\nSee console for details.`;
new Notice(message);
}

if (
this.data.format.notificationLevel === 'light' ||
this.data.format.notificationLevel === 'verbose'
) {
new Notice('ICS: Calendar download finished!');
}

return events;
}

Expand Down
2 changes: 2 additions & 0 deletions src/settings/ICSSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface ICSSettings {
format: {
timeFormat: string
dataViewSyntax: boolean,
notificationLevel: 'none' | 'light' | 'verbose';
},
calendars: Record < string, Calendar > ;
}
Expand Down Expand Up @@ -38,6 +39,7 @@ export const DEFAULT_SETTINGS: ICSSettings = {
format: {
timeFormat: "HH:mm",
dataViewSyntax: false,
notificationLevel: 'none'
},
calendars: {
}
Expand Down
38 changes: 38 additions & 0 deletions src/settings/ICSSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ export default class ICSSettingsTab extends PluginSettingTab {
return descEl;
}

private notificationLevelDescription(): DocumentFragment {
const descEl = document.createDocumentFragment();
descEl.appendText('Choose how many notifications you want ICS to display.');
descEl.appendChild(document.createElement('br'));
descEl.appendChild(document.createElement('br'));

const noneB = descEl.appendChild(document.createElement('b'));
noneB.appendText('None: ');
descEl.appendText('No notifications.');

descEl.appendChild(document.createElement('br'));
const lightB = descEl.appendChild(document.createElement('b'));
lightB.appendText('Light: ');
descEl.appendText('When starting and finishing overall download.');
descEl.appendChild(document.createElement('br'));

const verboseB = descEl.appendChild(document.createElement('b'));
verboseB.appendText('Verbose: ');
descEl.appendText('Overall + per calendar download notifications.');
return descEl;
}

display(): void {
let {
containerEl
Expand Down Expand Up @@ -186,6 +208,22 @@ export default class ICSSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));

const notificationLevelSetting = new Setting(containerEl)
.setName('Notification Level')
.setDesc(this.notificationLevelDescription())
.addDropdown((component) => {
component
.addOption('none', 'None')
.addOption('light', 'Light')
.addOption('verbose', 'Verbose')
.setValue(this.plugin.data.format.notificationLevel || 'none')
.onChange(async (v) => {
this.plugin.data.format.notificationLevel = v as 'none' | 'light' | 'verbose';
await this.plugin.saveSettings();
});
});


// Sponsor link - Thank you!
const divSponsor = containerEl.createDiv();
divSponsor.innerHTML = `<br/><hr/>A scratch my own itch project by <a href="https://muness.com/" target='_blank'>muness</a>.<br/>
Expand Down