-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
142 lines (125 loc) · 4.14 KB
/
App.tsx
File metadata and controls
142 lines (125 loc) · 4.14 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { useState, useEffect } from "react";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';
import { ThemeProvider } from "./context/ThemeContext";
import { Settings } from "./components/ApiSettings";
import { PromptSettings } from "./components/PromptSettings";
import { Sidebar } from "./components/Sidebar";
import { InfoPage } from "./components/InfoPage";
import { History } from "./components/History";
import { Dashboard } from "./components/Dashboard";
interface Settings {
openai_model: string;
custom_prompts: {
[key: string]: string;
};
prompt_order: string[];
selected_tone?: string;
first_visit_complete?: boolean;
shortcut_enabled?: boolean;
shortcut_keys?: string;
theme?: string;
}
function App() {
const [settings, setSettings] = useState<Settings>({
openai_model: "",
custom_prompts: {},
prompt_order: [],
first_visit_complete: false,
shortcut_enabled: true
});
const [activeSection, setActiveSection] = useState("info");
const [loading, setLoading] = useState(true);
useEffect(() => {
console.log("App mounted, loading settings...");
// Initialize notifications
async function initNotifications() {
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
}
initNotifications();
// Listen for notifications
const unlistenNotification = listen('notification', (event) => {
sendNotification({
title: 'Milo',
body: event.payload as string,
icon: '/icon.png'
});
});
// Load settings
invoke("get_settings")
.then((savedSettings: any) => {
setSettings(savedSettings as any as Settings);
// Set initial section based on whether it's first visit
if (!savedSettings.first_visit_complete) {
setActiveSection('info');
} else {
setActiveSection('dashboard');
}
setLoading(false);
})
.catch(console.error);
const unlisten = listen("transform_clipboard", async () => {
try {
console.log("Starting clipboard transformation...");
// Get latest settings before transforming
const currentSettings = await invoke<Settings>("get_settings");
console.log("Using tone:", currentSettings.selected_tone);
await invoke("transform_clipboard", {
promptKey: currentSettings.selected_tone || "Improve Writing",
});
console.log("Clipboard transformation complete");
} catch (error) {
console.error("Failed to transform clipboard:", error);
}
});
// Listen for navigation events from tray
const unlistenNavigate = listen('navigate-to-section', (event) => {
const section = event.payload as string;
console.log('Navigation event received:', section);
setActiveSection(section);
});
return () => {
unlisten.then((fn) => fn());
unlistenNotification.then(fn => fn());
unlistenNavigate.then(fn => fn());
};
}, []);
const renderContent = () => {
if (loading) {
return <div className="flex items-center justify-center min-h-screen text-text-secondary">Loading...</div>;
}
switch (activeSection) {
case 'info':
return <InfoPage />;
case 'prompts':
return <PromptSettings settings={settings} setSettings={setSettings} />;
case 'api':
return <Settings />;
case 'history':
return <History />;
case 'dashboard':
return <Dashboard />;
default:
return <PromptSettings settings={settings} setSettings={setSettings} />;
}
};
return (
<ThemeProvider>
<Sidebar
activeSection={activeSection}
onSectionChange={setActiveSection}
/>
<div className="ml-14 min-h-screen">
<div className="mx-auto px-8 py-8 max-w-3xl">
{renderContent()}
</div>
</div>
</ThemeProvider>
);
}
export default App;