-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshim.html
More file actions
349 lines (299 loc) · 12 KB
/
Copy pathshim.html
File metadata and controls
349 lines (299 loc) · 12 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FocusAny Shim Test</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
padding: 20px;
background: #f5f5f5;
margin: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 10px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
font-size: 16px;
}
.button-group {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 30px;
}
button {
background: linear-gradient(135deg, #007AFF, #0056CC);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.3s ease;
min-width: 120px;
}
button:hover {
background: linear-gradient(135deg, #0056CC, #003D99);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}
button:active {
transform: translateY(0);
}
.success {
background: linear-gradient(135deg, #52c41a, #389e0d);
}
.error {
background: linear-gradient(135deg, #ff4d4f, #cf1322);
}
.info {
background: linear-gradient(135deg, #1890ff, #096dd9);
}
#log {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 20px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 13px;
line-height: 1.5;
max-height: 400px;
overflow-y: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
.status {
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
border-left: 4px solid #2196f3;
background: #e3f2fd;
}
.log-entry {
margin-bottom: 5px;
padding: 2px 0;
}
.log-time {
color: #666;
font-weight: bold;
}
.log-success {
color: #52c41a;
}
.log-error {
color: #ff4d4f;
}
.log-info {
color: #1890ff;
}
</style>
</head>
<body>
<div class="container">
<h1>🚀 FocusAny Shim Version Test</h1>
<div class="status">
<strong>Status:</strong> <span id="status">Initializing...</span>
</div>
<div class="button-group">
<button onclick="testBasicNotification()">📢 Basic Notification</button>
<button onclick="testSuccessToast()" class="success">✅ Success Toast</button>
<button onclick="testErrorToast()" class="error">❌ Error Toast</button>
<button onclick="testInfoToast()" class="info">ℹ️ Info Toast</button>
<button onclick="testLongDuration()">⏰ Long Duration</button>
<button onclick="testZeroDuration()">🔄 Permanent Notification</button>
<button onclick="testCopyText()">📋 Copy Text</button>
<button onclick="testPlatformDetection()">💻 Platform Detection</button>
<button onclick="testDbOperations()">💾 Database Operations</button>
<button onclick="clearLog()">🗑️ Clear Log</button>
</div>
<h3>📋 Execution Log:</h3>
<div id="log">Waiting for test...</div>
</div>
<!-- Load Babel-transformed FocusAny Shim -->
<script src="focusany-shim-browser.min.js"></script>
<script>
// 日志记录函数
function addLog(message, type = 'info') {
const log = document.getElementById('log');
const time = new Date().toLocaleTimeString();
const logEntry = document.createElement('div');
logEntry.className = `log-entry log-${type}`;
logEntry.innerHTML = `<span class="log-time">[${time}]</span> ${message}`;
log.appendChild(logEntry);
log.scrollTop = log.scrollHeight;
}
function clearLog() {
document.getElementById('log').innerHTML = '';
addLog('Log cleared');
}
function updateStatus(message, type = 'info') {
const status = document.getElementById('status');
status.textContent = message;
status.className = `log-${type}`;
}
// Test functions
function testBasicNotification() {
addLog('=== Testing Basic Notification ===');
try {
window.focusany.showNotification("This is a basic notification test");
addLog('✅ Basic notification call successful', 'success');
} catch (e) {
addLog('❌ Basic notification call failed: ' + e.message, 'error');
}
}
function testSuccessToast() {
addLog('=== Testing Success Toast ===');
try {
window.focusany.showToast("Operation executed successfully!", { status: "success", duration: 3000 });
addLog('✅ Success toast call successful', 'success');
} catch (e) {
addLog('❌ Success toast call failed: ' + e.message, 'error');
}
}
function testErrorToast() {
addLog('=== Testing Error Toast ===');
try {
window.focusany.showToast("An error occurred!", { status: "error", duration: 4000 });
addLog('✅ Error toast call successful', 'success');
} catch (e) {
addLog('❌ Error toast call failed: ' + e.message, 'error');
}
}
function testInfoToast() {
addLog('=== Testing Info Toast ===');
try {
window.focusany.showToast("This is an information message", { status: "info", duration: 2000 });
addLog('✅ Info toast call successful', 'success');
} catch (e) {
addLog('❌ Info toast call failed: ' + e.message, 'error');
}
}
function testLongDuration() {
addLog('=== Testing Long Duration Notification ===');
try {
window.focusany.showToast("This notification will display for 10 seconds", { duration: 10000 });
addLog('✅ Long duration notification call successful', 'success');
} catch (e) {
addLog('❌ Long duration notification call failed: ' + e.message, 'error');
}
}
function testZeroDuration() {
addLog('=== Testing Permanent Notification ===');
try {
window.focusany.showToast("This notification won't disappear automatically, click X to close", { duration: 0 });
addLog('✅ Permanent notification call successful', 'success');
} catch (e) {
addLog('❌ Permanent notification call failed: ' + e.message, 'error');
}
}
function testCopyText() {
addLog('=== Testing Copy Text ===');
try {
const result = window.focusany.copyText("Hello from FocusAny Shim!");
if (result) {
addLog('✅ Text copied successfully', 'success');
window.focusany.showToast("Text has been copied to clipboard", { status: "success" });
} else {
addLog('❌ Text copy failed', 'error');
}
} catch (e) {
addLog('❌ Copy text call failed: ' + e.message, 'error');
}
}
function testPlatformDetection() {
addLog('=== Testing Platform Detection ===');
try {
const isMac = window.focusany.isMacOs();
const isWindows = window.focusany.isWindows();
const isLinux = window.focusany.isLinux();
addLog(`macOS: ${isMac}, Windows: ${isWindows}, Linux: ${isLinux}`);
addLog('✅ Platform detection completed', 'success');
let platform = 'Unknown';
if (isMac) platform = 'macOS';
else if (isWindows) platform = 'Windows';
else if (isLinux) platform = 'Linux';
window.focusany.showToast(`Detected platform: ${platform}`, { status: "info" });
} catch (e) {
addLog('❌ Platform detection failed: ' + e.message, 'error');
}
}
function testDbOperations() {
addLog('=== Testing Database Operations ===');
try {
// Test write
const doc = {
_id: 'test-' + Date.now(),
name: 'Test Document',
content: 'This is a test document',
timestamp: new Date().toISOString()
};
const putResult = window.focusany.db.put(doc);
addLog(`Document written: ${JSON.stringify(putResult)}`);
// Test read
const getResult = window.focusany.db.get(doc._id);
addLog(`Document read: ${JSON.stringify(getResult)}`);
// Test query all
const allDocs = window.focusany.db.allDocs();
addLog(`Total documents: ${allDocs.length}`);
addLog('✅ Database operations test completed', 'success');
window.focusany.showToast("Database operations test completed", { status: "success" });
} catch (e) {
addLog('❌ Database operations failed: ' + e.message, 'error');
}
}
// Check after page load is complete
document.addEventListener('DOMContentLoaded', function () {
addLog('Page loading complete');
setTimeout(() => {
if (window.focusany) {
addLog('✅ FocusAny Shim loaded successfully', 'success');
updateStatus('✅ FocusAny Shim ready', 'success');
// Test available methods
const methods = ['showNotification', 'showToast', 'copyText', 'isMacOs', 'isWindows', 'isLinux'];
const availableMethods = methods.filter(method => {
try {
return typeof window.focusany[method] === 'function';
} catch (e) {
return false;
}
});
addLog(`Available methods: ${availableMethods.join(', ')}`);
// Automatically display welcome message
window.focusany.showToast("FocusAny Shim Babel version loaded successfully!", {
status: "success",
duration: 3000
});
} else {
addLog('❌ FocusAny Shim failed to load', 'error');
updateStatus('❌ FocusAny Shim failed to load', 'error');
}
}, 100);
});
// Monitor console output
const originalLog = console.log;
const originalError = console.error;
console.log = function (...args) {
addLog('Console.log: ' + args.join(' '));
originalLog.apply(console, args);
};
console.error = function (...args) {
addLog('Console.error: ' + args.join(' '), 'error');
originalError.apply(console, args);
};
</script>
</body>
</html>