-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
81 lines (68 loc) · 2.59 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
import { App, Plugin } from "obsidian";
import { NotionMigrationSettingTab } from "./src/ui/NotionMigrationSettingTab";
import { NotionMigrationSettings, DEFAULT_SETTINGS } from "./src/interfaces/PluginSettings";
import { ImportControl } from "./src/interfaces/NotionTypes";
export default class NotionMigrationPlugin extends Plugin {
settings: NotionMigrationSettings;
importControl: ImportControl = {
isImporting: false,
forceStop: false
};
statusBarItem: HTMLElement;
// Animation for status text
private statusAnimationInterval: number | null = null;
private animationDots = 0;
async onload() {
await this.loadSettings();
this.addSettingTab(new NotionMigrationSettingTab(this.app, this));
// Create the status bar item (initially hidden)
this.statusBarItem = this.addStatusBarItem();
this.statusBarItem.addClass('notion-import-status');
this.statusBarItem.style.display = 'none';
}
async onunload() {
// Clean up status bar and any running animations
this.stopStatusAnimation();
if (this.statusBarItem) {
this.statusBarItem.remove();
}
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
getApp(): App {
return this.app;
}
// Method to show the import status in the status bar
showImportStatus() {
this.statusBarItem.setText('Migrating content from Notion');
this.statusBarItem.style.display = 'block';
// Create animation effect for the text
this.startStatusAnimation();
}
// Method to hide the import status from the status bar
hideImportStatus() {
this.statusBarItem.style.display = 'none';
// Stop animation if it exists
this.stopStatusAnimation();
}
private startStatusAnimation() {
// Clear any existing animation
this.stopStatusAnimation();
// Start a new animation
this.statusAnimationInterval = window.setInterval(() => {
this.animationDots = (this.animationDots % 3) + 1;
const dots = '.'.repeat(this.animationDots);
this.statusBarItem.setText(`Migrating content from Notion${dots}`);
}, 500); // Update every 500ms
}
private stopStatusAnimation() {
if (this.statusAnimationInterval) {
clearInterval(this.statusAnimationInterval);
this.statusAnimationInterval = null;
}
}
}