Skip to content

Commit 6f0c78e

Browse files
committed
Reviewer changes implemented
1 parent 7edfd56 commit 6f0c78e

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

main.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
} from "obsidian";
1111

1212
// Define the constant for the ClockView type
13-
const ClockViewType = "my-clock-view";
13+
const ClockViewType = "tokei";
1414

1515
// Define the ClockView class that extends ItemView
1616
class ClockView extends ItemView {
1717
private readonly plugin: ClockPlugin;
18-
private updateInterval: NodeJS.Timeout | null = null;
18+
private updateInterval: number | null = null;
1919
// Container elements for time, date, and timezone
2020
private timeDateContainer: HTMLElement;
2121
private timezoneContainer: HTMLElement;
@@ -35,13 +35,13 @@ class ClockView extends ItemView {
3535
// Called when the view is opened
3636
public async onOpen(): Promise<void> {
3737
this.displayTime();
38-
this.updateInterval = setInterval(this.displayTime.bind(this), 1000);
38+
this.updateInterval = window.setInterval(this.displayTime.bind(this), 1000);
3939
}
4040

4141
// Called when the view is closed
4242
public onClose(): Promise<void> {
43-
if (this.updateInterval) {
44-
clearInterval(this.updateInterval);
43+
if (this.updateInterval !== null) {
44+
window.clearInterval(this.updateInterval);
4545
this.updateInterval = null;
4646
}
4747
return super.onClose();
@@ -269,43 +269,30 @@ export default class ClockPlugin extends Plugin {
269269
DEFAULT_SETTINGS,
270270
await this.loadData()
271271
);
272-
272+
273273
this.registerView(
274274
ClockViewType,
275275
(leaf) => (this.view = new ClockView(leaf, this))
276276
);
277-
277+
278278
this.addCommand({
279279
id: "open",
280280
name: "open",
281281
callback: this.onShow.bind(this),
282282
});
283-
284-
let isViewInitialized = false;
285-
286-
const checkLayoutInterval = setInterval(async () => {
287-
if (this.app.workspace.layoutReady && !isViewInitialized) {
288-
await this.initView();
289-
isViewInitialized = true;
290-
clearInterval(checkLayoutInterval);
291-
}
292-
}, 1000);
293-
283+
294284
this.app.workspace.onLayoutReady(async () => {
295-
if (!isViewInitialized) {
296-
await this.initView();
297-
isViewInitialized = true;
298-
clearInterval(checkLayoutInterval);
299-
}
285+
await this.initView();
300286
});
301-
287+
302288
this.addSettingTab(new ClockSettingTab(this.app, this));
303289
}
290+
304291

305292
// Clear the update interval when the plugin is unloaded
306293
public onunload(): void {
307-
if (this.updateInterval) {
308-
clearInterval(this.updateInterval);
294+
if (this.updateInterval !== null) {
295+
window.clearInterval(this.updateInterval);
309296
this.updateInterval = null;
310297
}
311298
}
@@ -381,10 +368,9 @@ class ClockSettingTab extends PluginSettingTab {
381368
donateImage.src =
382369
"https://cdn.buymeacoffee.com/buttons/v2/default-blue.png";
383370
donateImage.alt = "Buy Me A Coffee";
384-
rotateColorRandomly(donateImage);
385-
donateImage.style.height = "60px";
386-
donateImage.style.width = "217px";
387371

372+
rotateColorRandomly(donateImage);
373+
donateImage.classList.add('donate-img');
388374
donateLink.appendChild(donateImage);
389375
donateText.appendChild(donateLink);
390376

@@ -468,7 +454,7 @@ class ClockSettingTab extends PluginSettingTab {
468454
await this.plugin.saveSettings();
469455

470456
const clockView = this.app.workspace
471-
.getLeavesOfType("my-clock-view")
457+
.getLeavesOfType("tokei")
472458
.find((leaf) => leaf.view instanceof ClockView);
473459
if (clockView) {
474460
(clockView.view as ClockView).displayTime();
@@ -674,7 +660,7 @@ class ClockSettingTab extends PluginSettingTab {
674660
await this.plugin.saveSettings();
675661

676662
const clockView = this.app.workspace
677-
.getLeavesOfType("my-clock-view")
663+
.getLeavesOfType("tokei")
678664
.find((leaf) => leaf.view instanceof ClockView);
679665
if (clockView) {
680666
// Update the clock immediately

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "tokei",
33
"name": "Tokei",
4-
"version": "0.4.0",
4+
"version": "0.5.0",
55
"minAppVersion": "0.16.3",
66
"description": "A simple clock.",
77
"author": "HiroMike",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Tokei",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "A simple clock.",
55
"main": "main.js",
66
"scripts": {

styles.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,16 @@
173173
margin-bottom: 5px;
174174
}
175175

176+
.donate-img {
177+
width: 163px;
178+
height: 45px !important;
179+
border-radius: 10px;
180+
}
181+
182+
.donate-img:hover {
183+
border: 2px solid red;
184+
border-radius: 10px;
185+
}
186+
176187

177188

0 commit comments

Comments
 (0)