-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
217 lines (167 loc) · 4.81 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting} from 'obsidian';
import { Mode, Timer } from './Pomodoro/pomodoro';
import { createDailyNote } from './Review/daily';
import { createDailyReview } from './Review/daily_review';
import { createWeeklyReview } from './Review/weekly_review';
import { createMonthlyReview } from './Review/monthly_review';
import { createQuarterlyReview } from './Review/quarterly_review';
import { createYearlyReview } from './Review/yearly_review';
// Remember to rename these classes and interfaces!
export interface MyPluginSettings {
mySetting: string;
pomodoroInterval: number;
pomo: number;
}
export const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default',
pomodoroInterval: 1,
pomo: 5,
}
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
statusBar: HTMLElement;
timer: Timer;
async onload() {
await this.loadSettings();
this.addRibbonIcon('clock', 'Pomodoro', (evt: MouseEvent) => {
this.timer.onRibbonIconClick();
});
// This creates an icon in the left ribbon.
const statusBarItemEl = this.addStatusBarItem();
statusBarItemEl.setText('Pomodoro time');
this.statusBar = this.addStatusBarItem();
this.timer = new Timer(this);
this.registerInterval(window.setInterval(async () =>
this.statusBar.setText(await this.timer.setStatusBarText()), 500));
this.addCommand({
id: 'start-pomo-timer',
name: 'Start pomodoro timer',
checkCallback: (checking: boolean) => {
if (this.timer.mode !== Mode.Pomo) {
if (!checking) {
this.timer.startTimer();
}
return true;
}
return false;
}
});
this.addCommand({
id: 'quit-statusbar-pomo',
name: 'Quit pomodoro timer',
checkCallback: (checking: boolean) => {
if (this.timer.mode !== Mode.NoTimer) {
if (!checking) {
this.timer.quitTimer();
}
return true;
}
return false;
}
});
// ... (daily note)
this.addCommand({
id: 'create-daily-note',
name: 'Create Daily Note',
callback: () => {
createDailyNote(this.app);
},
});
//daily review
this.addCommand({
id: 'create-daily-review',
name: 'Create Daily Review',
callback: () => {
createDailyReview(this.app);
},
});
//weekly review
this.addCommand({
id: 'create-weekly-review',
name: 'Create Weekly Review',
callback: () => {
createWeeklyReview(this.app);
},
});
//monthly review
this.addCommand({
id: 'create-monthly-review',
name: 'Create Monthly Review',
callback: () => {
createMonthlyReview(this.app);
},
});
//quarterly review
this.addCommand({
id: 'Quarterly Review',
name: 'Create Quarterly Review',
callback: () => {
createQuarterlyReview(this.app);
},
});
//yearly review
this.addCommand({
id: 'Yearly Review',
name: 'Create Yearly Review',
callback: () => {
createYearlyReview(this.app);
},
});
// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SampleSettingTab(this.app, this));
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
console.log('click', evt);
});
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}
class SampleModal extends Modal {
constructor(app: App) {
super(app);
}
onOpen() {
const { contentEl } = this;
contentEl.setText('Woah!');
}
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}
class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h3', { text: 'Pomodoro' });
/************** Pomodoro settings **************/
const pomodoroInterval = new Setting(containerEl)
.setName('Pomodoro interval')
.setDesc(`${this.plugin.settings.pomo} minutes`)
.addSlider(slider => {
slider
.setValue(this.plugin.settings.pomo)
.setLimits(0, 500, 1) // Adjust the limits as needed
.onChange(async (value) => {
this.plugin.settings.pomo = value;
await this.plugin.saveSettings();
pomodoroInterval.descEl.setText(`${value} minutes`);
});
});
}
}