-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.html
388 lines (356 loc) · 14.2 KB
/
settings.html
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!-- settings.html -->
<!DOCTYPE html>
<html>
<head>
<title>Settings</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.section {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}
.routing-container {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.routing-container input {
margin-right: 5px;
}
/* Slider Styles */
.slider-container {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.slider-container input[type="range"] {
width: 100%;
margin-right: 10px;
}
.slider-value {
width: 30px;
text-align: center;
font-weight: bold;
}
/* Theme Selection Styles */
.theme-container {
margin-bottom: 20px;
}
/* Update Button Styles */
#update-settings {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
}
#update-settings:disabled {
background-color: #a5d6a7;
cursor: not-allowed;
}
.pickr button {
border: 1px solid black;
}
</style>
<!-- Include Pickr CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/themes/classic.min.css"/> <!-- 'classic' theme -->
</head>
<body>
<h2>Settings</h2>
<!-- Connection Routing Options -->
<div class="section">
<label>Connection Routing:</label>
<div class="routing-container">
<input type="radio" id="routing-none" name="connectionRouting" value="none">
<label for="routing-none">None</label>
<input type="radio" id="routing-orthogonal" name="connectionRouting" value="orthogonal">
<label for="routing-orthogonal">Orthogonal</label>
<input type="radio" id="routing-bezier" name="connectionRouting" value="bezier">
<label for="routing-bezier">Bezier</label>
</div>
</div>
<!-- Pre-Made Themes Selection -->
<div class="section theme-container">
<label for="theme-select">Pre-Made Themes:</label>
<select id="theme-select">
<option value="">-- Select a Theme --</option>
<!-- Themes will be populated dynamically -->
</select>
</div>
<!-- Grid Size Slider -->
<div class="section">
<label for="grid-size">Grid Size (px):</label>
<div class="slider-container">
<input type="range" id="grid-size" name="grid-size" min="5" max="50" step="5" list="tickmarks">
<datalist id="tickmarks">
<option value="5"></option>
<option value="10"></option>
<option value="50"></option>
</datalist>
<span class="slider-value" id="grid-size-value">50</span>
</div>
</div>
<!-- Background Color Picker -->
<div class="section">
<label for="background-color">Background Color:</label>
<div id="background-color-picker"></div>
</div>
<!-- Update Settings Button -->
<button id="update-settings" disabled>Update Settings</button>
<!-- Include Pickr JS -->
<script src="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.min.js"></script>
<script>
// Define pre-made themes
const themes = [
{
name: 'Default',
gridLineColor: '#e0e0e0',
postItColor: 'rgba(255, 255, 0, 1)', // Yellow
connectionLineColor: '#000000', // Black
backgroundColor: '#ffffff' // White
},
{
name: 'Dark Mode',
gridLineColor: '#555555',
postItColor: '#E2E2B6', // Beige
connectionLineColor: '#E2E2B6', // Light Blue
backgroundColor: '#021526' // Dark Blue
},
{
name: 'Ocean Blue',
gridLineColor: '#a0c4ff',
postItColor: '#3DC2EC', // Light Blue
connectionLineColor: '#1e90ff', // Dodger Blue
backgroundColor: '#f0f8ff' // Alice Blue
},
{
name: 'Plum Blossom',
gridLineColor: '#704264',
postItColor: '#DBAFA0', // Light Blue
connectionLineColor: '#BB8493', // Dodger Blue
backgroundColor: '#49243E' // Alice Blue
},
{
name: 'Tree Stump',
gridLineColor: '#3C2A21',
postItColor: '#E5E5CB', // Light Blue
connectionLineColor: '#D5CEA3', // Dodger Blue
backgroundColor: '#1A120B' // Alice Blue
},
{
name: 'Autumn Embers',
gridLineColor: '#553939',
postItColor: '#A77979', // Light Blue
connectionLineColor: '#704F4F', // Dodger Blue
backgroundColor: '#472D2D' // Alice Blue
},
{
name: 'Morning Breeze',
gridLineColor: '#81BFDA',
postItColor: '#F5F0CD', // Light Blue
connectionLineColor: '#F0BB78', // Dodger Blue
backgroundColor: '#B1F0F7' // Alice Blue
},
{
name: 'Strawberry Cake',
gridLineColor: '#F2F9FF',
postItColor: '#FFCCE1', // Tomato
connectionLineColor: '#E195AB', // Tomato
backgroundColor: '#FFF5D7' // Misty Rose
},
{
name: 'Squid Ink',
gridLineColor: '#5E686D',
postItColor: '#FAFFC5', // Tomato
connectionLineColor: '#FAFFC5', // Tomato
backgroundColor: '#3A3960' // Misty Rose
},
{
name: 'Sunset',
gridLineColor: '#ffb3ba',
postItColor: 'rgba(255, 99, 71, 1)', // Tomato
connectionLineColor: '#ff6347', // Tomato
backgroundColor: '#ffe4e1' // Misty Rose
},
{
name: 'Forest',
gridLineColor: '#98fb98',
postItColor: 'rgba(34, 139, 34, 1)', // Forest Green
connectionLineColor: '#228b22', // Forest Green
backgroundColor: '#f5fffa' // Mint Cream
}
];
// Current settings state
let currentSettings = {
connectionRouting: 'bezier',
gridSize: 50,
backgroundColor: '#ffffff',
gridLineColor: '#e0e0e0', // Default grid line color
postItColor: 'rgba(255, 255, 0, 1)', // Default post-it color
connectionLineColor: '#000000' // Default connection line color
};
// Track changes
let isChanged = false;
// Elements
const routingRadios = document.querySelectorAll('input[name="connectionRouting"]');
const gridSizeSlider = document.getElementById('grid-size');
const gridSizeValue = document.getElementById('grid-size-value');
const updateButton = document.getElementById('update-settings');
const themeSelect = document.getElementById('theme-select');
// Populate Themes Dropdown
themes.forEach((theme, index) => {
const option = document.createElement('option');
option.value = index; // Use index as value to reference the theme
option.textContent = theme.name;
themeSelect.appendChild(option);
});
// Initialize Pickr
const pickr = Pickr.create({
el: '#background-color-picker',
theme: 'classic', // or 'monolith', or 'nano'
default: currentSettings.backgroundColor,
swatches: [
'#ffffff', '#000000', '#ff0000', '#00ff00', '#0000ff',
'#ffff00', '#ff00ff', '#00ffff', '#cccccc', '#ffcccc'
],
components: {
preview: true,
opacity: true,
hue: true,
interaction: {
hex: true,
rgba: true,
hsla: true,
hsva: true,
cmyk: true,
input: true,
clear: true,
save: true
}
}
});
// Handle Pickr color changes
pickr.on('change', (color, instance) => {
const selectedColor = color.toHEXA().toString(); // Use HEXA for consistency
if (selectedColor !== currentSettings.backgroundColor) {
isChanged = true;
updateButton.disabled = false;
}
});
// Handle Pickr save event to close the picker
pickr.on('save', (color, instance) => {
const selectedColor = color.toHEXA().toString();
// Update the background color input value if needed
if (selectedColor !== currentSettings.backgroundColor) {
isChanged = true;
updateButton.disabled = false;
}
pickr.hide(); // Automatically close the Pickr popup
});
// Handle Connection Routing changes
routingRadios.forEach((radio) => {
radio.addEventListener('change', (event) => {
if (event.target.checked && event.target.value !== currentSettings.connectionRouting) {
isChanged = true;
updateButton.disabled = false;
}
});
});
// Handle Grid Size slider changes
gridSizeSlider.addEventListener('input', (event) => {
const validValues = [5, 10, 50];
let closestValue = validValues.reduce((prev, curr) =>
Math.abs(curr - gridSizeSlider.value) < Math.abs(prev - gridSizeSlider.value) ? curr : prev
);
gridSizeSlider.value = closestValue;
gridSizeValue.textContent = closestValue;
const newValue = parseInt(event.target.value, 10);
gridSizeValue.textContent = newValue;
if (newValue !== currentSettings.gridSize) {
isChanged = true;
updateButton.disabled = false;
}
});
// Handle Theme Selection changes
themeSelect.addEventListener('change', (event) => {
const selectedIndex = event.target.value;
if (selectedIndex === "") {
// Reset to default settings or keep current settings
// Here, we'll do nothing
return;
}
const selectedTheme = themes[selectedIndex];
if (selectedTheme) {
// Update current settings with the selected theme's settings
currentSettings.gridLineColor = selectedTheme.gridLineColor;
currentSettings.postItColor = selectedTheme.postItColor;
currentSettings.connectionLineColor = selectedTheme.connectionLineColor;
currentSettings.backgroundColor = selectedTheme.backgroundColor;
// Update UI elements to reflect the theme's settings
// Update Pickr color
pickr.setColor(selectedTheme.backgroundColor);
// If you have additional color pickers for gridLineColor and connectionLineColor,
// you should initialize and update them similarly. For brevity, assuming they are not
// present in the current settings page.
// Optionally, you can update other UI elements or inputs if they exist
// Mark as changed
isChanged = true;
updateButton.disabled = false;
}
});
// Listen for 'settings-changed' to update the inputs
electronAPI.onSettingsChanged((newSettings) => {
currentSettings = { ...currentSettings, ...newSettings };
// Update Connection Routing Radio Buttons
if (newSettings.connectionRouting) {
const selectedRadio = document.querySelector(`input[name="connectionRouting"][value="${newSettings.connectionRouting}"]`);
if (selectedRadio) selectedRadio.checked = true;
}
// Update Grid Size Slider and Display
if (newSettings.gridSize) {
gridSizeSlider.value = newSettings.gridSize;
gridSizeValue.textContent = newSettings.gridSize;
}
// Update Pickr Color
if (newSettings.backgroundColor) {
pickr.setColor(newSettings.backgroundColor);
}
// Reset change tracking
isChanged = false;
updateButton.disabled = true;
});
// Request current settings when the settings window loads
window.onload = () => {
electronAPI.requestSettings();
};
// Handle Update Settings button click
updateButton.addEventListener('click', () => {
// Gather updated settings
const updatedSettings = {
connectionRouting: document.querySelector('input[name="connectionRouting"]:checked').value,
gridSize: parseInt(gridSizeSlider.value, 10),
backgroundColor: pickr.getColor().toHEXA().toString(),
gridLineColor: currentSettings.gridLineColor,
postItColor: currentSettings.postItColor,
connectionLineColor: currentSettings.connectionLineColor
};
// Send updated settings via IPC
electronAPI.updateSettings(updatedSettings);
// Update current settings state
currentSettings = { ...currentSettings, ...updatedSettings };
// Reset change tracking
isChanged = false;
updateButton.disabled = true;
});
</script>
</body>
</html>