forked from mountain-loop/yaak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tsx
More file actions
54 lines (46 loc) · 1.62 KB
/
main.tsx
File metadata and controls
54 lines (46 loc) · 1.62 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
import './main.css';
import { RouterProvider } from '@tanstack/react-router';
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
import { type } from '@tauri-apps/plugin-os';
import { changeModelStoreWorkspace, initModelStore } from '@yaakapp-internal/models';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { initSync } from './init/sync';
import { jotaiStore } from './lib/jotai';
import { router } from './lib/router';
import('react-pdf').then(({ pdfjs }) => {
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url,
).toString();
});
// Hide decorations here because it doesn't work in Rust for some reason (bug?)
const osType = type();
if (osType !== 'macos') {
await getCurrentWebviewWindow().setDecorations(false);
}
document.documentElement.setAttribute('data-platform', osType);
window.addEventListener('keydown', (e) => {
const rx = /input|select|textarea/i;
const target = e.target;
if (e.key !== 'Backspace') return;
if (!(target instanceof Element)) return;
if (target.getAttribute('contenteditable') !== null) return;
if (
!rx.test(target.tagName) ||
('disabled' in target && target.disabled) ||
('readOnly' in target && target.readOnly)
) {
e.preventDefault();
}
});
// Initialize a bunch of watchers
initSync();
initModelStore(jotaiStore);
await changeModelStoreWorkspace(null); // Load global models
console.log('Creating React root');
createRoot(document.getElementById('root') as HTMLElement).render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
);