-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.ts
More file actions
127 lines (109 loc) · 10.3 KB
/
Copy pathmain.ts
File metadata and controls
127 lines (109 loc) · 10.3 KB
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
import { ItemView, WorkspaceLeaf, Plugin, addIcon, FileSystemAdapter, Notice, App } from 'obsidian';
import { StatusBar } from './components/statusbar/StatusBar';
import { Sidebar } from './components/sidebar/SideBar';
import { Visualisation } from './components/visualisation/Visualisation';
import { initializeDatabase, clearDatabase } from 'sqlite/sqlHandler';
import path from 'path';
import fs from 'fs';
export default class MyPlugin extends Plugin {
private statusBarComponent: StatusBar;
statusBar: HTMLElement;
async onload() {
//creating env file if not exists
createEnvFile();
this.registerView('my-sidebar', (leaf: WorkspaceLeaf) => new Sidebar(leaf));
this.registerView('my-visualisation', leaf => new Visualisation(leaf));
this.statusBarComponent = new StatusBar(this);
initializeDatabase();
//clearDatabase();
const svgIcon = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!-- Creator: CorelDRAW -->
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="110px" height="110px" version="1.0" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
viewBox="0 0 424.95 315.53"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xodm="http://www.corel.com/coreldraw/odm/2003">
<defs>
<style type="text/css">
<![CDATA[
.stroke { stroke: black; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fil1 {fill:black}
.fil0 {fill:black;fill-rule:nonzero}
]]>
</style>
</defs>
<g id="Layer_x0020_1">
<metadata id="CorelCorpID_0Corel-Layer"/>
<g id="_1787182726528">
<path class="fil0" d="M284.66 258.16l-8.28 14.12c-1.23,2.09 -2.88,3.74 -4.83,4.86 -1.96,1.12 -4.21,1.72 -6.61,1.72l-6.55 0c-1.15,0 -2.2,0.15 -3.2,0.46 -1,0.31 -1.96,0.79 -2.89,1.44l-16.37 11.36c-1.15,0.8 -2.34,1.39 -3.59,1.78 -1.25,0.4 -2.56,0.59 -3.96,0.59l-50.61 0c-1.86,0 -3.6,-0.35 -5.21,-1.03 -1.6,-0.68 -3.05,-1.7 -4.34,-3.05l-32.7 -34.2 150.27 0 -1.14 1.94zm-10.49 12.82l7.14 -12.18 -139.76 0 28.52 29.83c1.05,1.09 2.22,1.92 3.5,2.46 1.28,0.55 2.69,0.82 4.21,0.82l50.61 0c1.15,0 2.2,-0.15 3.19,-0.46 1,-0.31 1.96,-0.79 2.89,-1.44l16.37 -11.36c1.15,-0.8 2.34,-1.39 3.59,-1.78 1.26,-0.39 2.56,-0.58 3.96,-0.58l6.55 0c1.96,0 3.78,-0.48 5.34,-1.38 1.57,-0.9 2.9,-2.23 3.89,-3.92z"/>
<path class="fil0" d="M137.44 64.74l8.28 -14.13c1.23,-2.09 2.88,-3.74 4.83,-4.86 1.96,-1.12 4.21,-1.72 6.61,-1.72l6.55 0c1.15,0 2.2,-0.15 3.2,-0.46 1,-0.31 1.96,-0.79 2.89,-1.44l16.37 -11.36c1.15,-0.8 2.34,-1.39 3.59,-1.78 1.25,-0.4 2.56,-0.59 3.96,-0.59l50.61 0c1.86,0 3.6,0.35 5.21,1.03 1.6,0.68 3.05,1.7 4.34,3.05l32.7 34.2 -150.27 0 1.14 -1.94zm10.49 -12.82l-7.14 12.18 139.76 0 -28.52 -29.83c-1.05,-1.09 -2.22,-1.92 -3.5,-2.46 -1.28,-0.55 -2.69,-0.82 -4.21,-0.82l-50.61 0c-1.15,0 -2.2,0.15 -3.2,0.46 -1,0.31 -1.96,0.79 -2.89,1.44l-16.37 11.36c-1.15,0.8 -2.34,1.39 -3.59,1.78 -1.26,0.39 -2.56,0.58 -3.96,0.58l-6.55 0c-1.96,0 -3.78,0.48 -5.34,1.38 -1.57,0.9 -2.9,2.23 -3.89,3.92z"/>
<path class="fil0" d="M98.92 160.15l36.41 0c0.16,0.87 0.33,1.73 0.52,2.59l-36.93 0 0 -2.59zm187.85 0l36.41 0 0 2.59 -36.93 0c0.19,-0.86 0.36,-1.72 0.52,-2.59z"/>
<path class="fil0" d="M209.76 315.53l0 -92.09c0.43,0.01 0.86,0.02 1.29,0.02 0.43,0 0.86,-0.01 1.28,-0.02l0 92.09 -2.57 0zm0 -230.93l0 -77.22 2.57 0 0 77.22 -2.57 0z"/>
<path class="fil0" d="M146.07 104.51l-38.21 -34.5 -69.62 0 0 -2.58 70.11 0 0.86 0.33 38.3 34.58c-0.49,0.72 -0.97,1.44 -1.43,2.18z"/>
<path class="fil0" d="M85.32 69.68l-29.97 -27.06 -44.89 -0.3 0.01 -2.57 45.38 0.31 0.85 0.33 30.33 27.39 -1.72 1.92z"/>
<path class="fil1" d="M10.46 34.96c3.33,0 6.03,2.71 6.03,6.06 0,3.35 -2.7,6.06 -6.03,6.06 -3.33,0 -6.03,-2.71 -6.03,-6.06 0,-3.35 2.7,-6.06 6.03,-6.06z"/>
<path class="fil1" d="M38.24 62.65c3.33,0 6.03,2.71 6.03,6.06 0,3.35 -2.7,6.06 -6.03,6.06 -3.33,0 -6.03,-2.71 -6.03,-6.06 0,-3.35 2.7,-6.06 6.03,-6.06z"/>
<path class="fil0" d="M240.82 84.59l17.66 -49.39 84.48 0 0 2.58 -82.68 0 -16.74 46.81 -2.72 0z"/>
<path class="fil0" d="M277.55 36.1l10.15 -31.04 79.03 -0.28 0 2.57 -77.16 0.28 -9.57 29.27 -2.44 -0.8z"/>
<path class="fil1" d="M366.73 0c-3.33,0 -6.03,2.71 -6.03,6.06 0,3.35 2.7,6.06 6.03,6.06 3.33,0 6.03,-2.71 6.03,-6.06 0,-3.35 -2.7,-6.06 -6.03,-6.06z"/>
<path class="fil1" d="M342.96 30.43c-3.33,0 -6.03,2.71 -6.03,6.06 0,3.35 2.7,6.06 6.03,6.06 3.33,0 6.03,-2.71 6.03,-6.06 0,-3.35 -2.7,-6.06 -6.03,-6.06z"/>
<path class="fil0" d="M148.19 190.76l-63.36 59.23 -0.87 0.35 -48.37 0 0 -2.59 47.87 0 63.27 -59.15c0.48,0.73 0.96,1.45 1.46,2.15z"/>
<path class="fil1" d="M35.58 255.1c3.33,0 6.03,-2.71 6.03,-6.06 0,-3.35 -2.7,-6.06 -6.03,-6.06 -3.33,0 -6.03,2.71 -6.03,6.06 0,3.35 2.7,6.06 6.03,6.06z"/>
<path class="fil0" d="M241.46 217.18l58.49 59.97 61.76 0 0 2.58 -62.83 0 -59.98 -61.5c0.86,-0.34 1.72,-0.69 2.56,-1.05z"/>
<path class="fil1" d="M359.73 284.51c-3.33,0 -6.03,-2.71 -6.03,-6.06 0,-3.35 2.7,-6.06 6.03,-6.06 3.33,0 6.03,2.71 6.03,6.06 0,3.35 -2.7,6.06 -6.03,6.06z"/>
<path class="fil0" d="M122.44 62.8l177.21 0c2.2,0 4.27,0.42 6.18,1.26 1.9,0.84 3.62,2.07 5.12,3.7l35.61 38.61c1.37,1.48 2.4,3.11 3.09,4.87 0.69,1.77 1.04,3.66 1.04,5.67l0 89.66c0,2.02 -0.35,3.93 -1.06,5.72 -0.7,1.78 -1.75,3.42 -3.13,4.89l-35.56 38.01c-1.5,1.6 -3.21,2.82 -5.1,3.64 -1.9,0.83 -3.96,1.25 -6.13,1.25l-177.32 0c-2.17,0 -4.23,-0.42 -6.13,-1.25 -1.9,-0.82 -3.61,-2.04 -5.1,-3.64l-35.56 -38.01c-1.39,-1.49 -2.44,-3.12 -3.14,-4.9 -0.7,-1.8 -1.05,-3.7 -1.05,-5.72l0 -89.66c0,-2.01 0.35,-3.9 1.04,-5.67 0.68,-1.75 1.71,-3.37 3.08,-4.86l35.61 -38.62c1.5,-1.63 3.22,-2.86 5.12,-3.7 1.91,-0.84 3.98,-1.26 6.18,-1.26zm177.21 5.17l-177.21 0c-1.51,0 -2.89,0.28 -4.13,0.82 -1.25,0.55 -2.39,1.38 -3.42,2.49l-35.61 38.61c-0.92,0.99 -1.61,2.07 -2.06,3.24 -0.45,1.15 -0.67,2.42 -0.67,3.79l0 89.66c0,1.4 0.23,2.68 0.68,3.83 0.47,1.17 1.17,2.26 2.11,3.26l35.56 38.01c1.02,1.09 2.16,1.91 3.39,2.45 1.23,0.53 2.6,0.8 4.1,0.8l177.32 0c1.5,0 2.88,-0.27 4.1,-0.8 1.23,-0.54 2.37,-1.36 3.39,-2.45l35.56 -38.01c0.95,-1.01 1.65,-2.1 2.11,-3.26 0.45,-1.15 0.68,-2.43 0.68,-3.83l0 -89.66c0,-1.38 -0.22,-2.64 -0.67,-3.79 -0.45,-1.16 -1.14,-2.24 -2.06,-3.24l-35.61 -38.61c-1.02,-1.11 -2.17,-1.94 -3.41,-2.49 -1.24,-0.54 -2.62,-0.82 -4.13,-0.82z"/>
<path class="fil0" d="M-0 209.42l101.11 0c1.31,0 2.33,0.38 3.38,1.31l30.1 26.74 153.43 0 64.22 -55.62c0.94,-0.77 1.91,-1.27 3.34,-1.27l48.84 0 0 10.31 -46.96 0 -64.22 55.62 -3.34 1.27 -157.23 0 -3.38 -1.31 -30.1 -26.73 -99.2 0 0 -10.31z"/>
<path class="fil0" d="M258.61 83.6c9.5,7.32 17.29,16.79 22.64,27.68 5.15,10.49 8.05,22.29 8.05,34.77 0,21.72 -8.76,41.38 -22.92,55.62 -14.16,14.23 -33.72,23.04 -55.33,23.04 -21.61,0 -41.17,-8.8 -55.33,-23.04 -14.16,-14.23 -22.92,-33.9 -22.92,-55.62 0,-12.48 2.9,-24.28 8.05,-34.77 5.35,-10.89 13.13,-20.36 22.64,-27.68l0.75 -0.26 93.61 0 0.75 0.26zm20.41 28.78c-5.12,-10.41 -12.53,-19.49 -21.58,-26.54l-92.77 0c-9.05,7.06 -16.47,16.13 -21.58,26.54 -4.98,10.15 -7.79,21.57 -7.79,33.67 0,21.03 8.48,40.07 22.19,53.85 13.71,13.78 32.65,22.3 53.57,22.3 20.92,0 39.86,-8.52 53.57,-22.3 13.71,-13.78 22.19,-32.82 22.19,-53.85 0,-12.09 -2.8,-23.52 -7.79,-33.67z"/>
<path class="fil0" d="M244.95 83.5c11.2,6.15 20.57,15.24 27.07,26.24 6.28,10.64 9.89,23.05 9.89,36.31 0,19.67 -7.93,37.48 -20.75,50.37 -12.82,12.89 -30.54,20.86 -50.1,20.86 -19.57,0 -37.28,-7.97 -50.1,-20.86 -12.82,-12.89 -20.75,-30.7 -20.75,-50.37 0,-13.26 3.61,-25.67 9.89,-36.31 6.5,-11 15.87,-20.1 27.07,-26.24l0.59 -0.16 66.62 0 0.59 0.16zm24.93 27.51c-6.22,-10.53 -15.15,-19.24 -25.83,-25.17l-66 0c-10.68,5.93 -19.61,14.64 -25.83,25.17 -6.06,10.26 -9.54,22.24 -9.54,35.04 0,18.98 7.65,36.16 20.02,48.6 12.37,12.44 29.46,20.13 48.34,20.13 18.88,0 35.97,-7.69 48.34,-20.13 12.37,-12.44 20.02,-29.62 20.02,-48.6 0,-12.8 -3.48,-24.78 -9.54,-35.04z"/>
<path class="fil0" d="M211.05 117.53c7.84,0 14.93,3.19 20.07,8.35 5.13,5.16 8.31,12.29 8.31,20.17 0,7.88 -3.18,15.01 -8.31,20.17 -5.13,5.16 -12.23,8.35 -20.07,8.35 -7.84,0 -14.93,-3.19 -20.07,-8.35 -5.13,-5.16 -8.31,-12.29 -8.31,-20.17 0,-7.88 3.18,-15.01 8.31,-20.17 5.13,-5.16 12.23,-8.35 20.07,-8.35zm18.3 10.12c-4.68,-4.71 -11.16,-7.62 -18.3,-7.62 -7.15,0 -13.62,2.91 -18.3,7.62 -4.68,4.71 -7.58,11.22 -7.58,18.4 0,7.19 2.9,13.69 7.58,18.4 4.68,4.71 11.16,7.62 18.3,7.62 7.15,0 13.62,-2.91 18.3,-7.62 4.68,-4.71 7.58,-11.21 7.58,-18.4 0,-7.19 -2.9,-13.69 -7.58,-18.4z"/>
<path class="fil0" d="M-0 190.02l133.72 -111.9c0.87,-0.68 1.82,-1.21 3.27,-1.21l152.2 0c1.37,0 2.12,0.26 3.22,1.17l102.85 84.29 29.68 0 0 10.31 -31.48 0c-1.17,0 -2.42,-0.53 -3.22,-1.17l-102.85 -84.29c-48.89,0 -99.78,0 -148.59,0l-138.8 116.15 0 -13.36z"/>
</g>
</g>
</svg>
`;
addIcon("textSightIcon", svgIcon);
this.addRibbonIcon("textSightIcon", "TextSight", () => {
this.navigateToSidebar();
});
}
navigateToSidebar() {
const leaves = this.app.workspace.getLeavesOfType('my-sidebar');
if (leaves.length > 0) {
this.app.workspace.setActiveLeaf(leaves[0]);
} else {
this.addSidebar();
}
}
addSidebar() {
if (this.app.workspace.getLeavesOfType('sidebar').length) {
return;
}
const rightLeaf = this.app.workspace.getRightLeaf(false);
if (rightLeaf) {
rightLeaf.setViewState({
type: 'my-sidebar',
active: true,
});
}
}
onunload() {
this.statusBar.remove();
}
}
export async function createEnvFile() {
try {
let adapter = app.vault.adapter;
let envPath = '';
if (adapter instanceof FileSystemAdapter) {
envPath = adapter.getBasePath();
}
envPath = path.join(envPath, './.obsidian/plugins/TextSight/.env');
if (!fs.existsSync(envPath)) {
fs.writeFileSync(envPath, 'OPENAI_API_KEY=ADD_KEY_HERE');
new Notice('A .env file has been created in the root of this plugin. Please add your API key for the TextSight plugin.');
}
} catch (error) {
console.error('Error creating .env file:', error);
}
}