-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
140 lines (112 loc) Β· 4.21 KB
/
Copy pathexample.ts
File metadata and controls
140 lines (112 loc) Β· 4.21 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
#!/usr/bin/env bun
/**
* FluxStack Desktop - Example Usage
*
* This example demonstrates how to use the enhanced desktop utilities
* that have been added to FluxStack Desktop.
*
* Usage: bun run example.ts
*/
import { open, createDesktopUtils } from './src'
async function main() {
console.log('π Starting FluxStack Desktop Example...')
try {
// Open a desktop window
console.log('π± Opening desktop window...')
const browser = await open('http://localhost:3000', {
windowSize: [1200, 800],
forceBrowser: 'chrome'
})
console.log('β
Desktop window opened successfully!')
// Create enhanced desktop utilities
const desktop = createDesktopUtils(browser)
// Wait a moment for the page to load
await new Promise(resolve => setTimeout(resolve, 2000))
// Example 1: Take a screenshot
console.log('πΈ Taking screenshot...')
await desktop.screenshot({
path: './example-screenshot.png',
format: 'png'
})
console.log('β
Screenshot saved to example-screenshot.png')
// Example 2: Show notification
console.log('π Showing notification...')
await desktop.showNotification({
title: 'FluxStack Desktop',
body: 'Example application is running!',
requireInteraction: false
})
// Example 3: Window management
console.log('πͺ Testing window management...')
await new Promise(resolve => setTimeout(resolve, 1000))
await desktop.maximize()
console.log('β
Window maximized')
await new Promise(resolve => setTimeout(resolve, 2000))
await desktop.setZoom(1.25)
console.log('β
Zoom set to 125%')
// Example 4: Page manipulation
console.log('π¨ Injecting custom CSS...')
await desktop.injectCSS(`
body {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%) !important;
color: white !important;
}
.container {
border: 3px solid #fff;
border-radius: 10px;
padding: 20px;
margin: 20px;
}
`)
console.log('β
Custom CSS injected')
// Example 5: File operations using Bun
console.log('π Testing file operations...')
const exampleData = {
timestamp: new Date().toISOString(),
message: 'Hello from FluxStack Desktop!',
version: desktop.getBunVersion()
}
await desktop.saveFile('./example-data.json', JSON.stringify(exampleData, null, 2))
console.log('β
Data saved to example-data.json')
const savedData = await desktop.readJSONFile('./example-data.json')
console.log('β
Data loaded from file:', savedData.message)
// Example 6: Clipboard operations
console.log('π Testing clipboard...')
await desktop.copyToClipboard('Hello from FluxStack Desktop clipboard!')
console.log('β
Text copied to clipboard')
const clipboardContent = await desktop.readFromClipboard()
console.log('β
Clipboard content:', clipboardContent)
// Example 7: System utilities
console.log('π οΈ System information:')
console.log(` Bun version: ${desktop.getBunVersion()}`)
console.log(` NODE_ENV: ${desktop.getEnv('NODE_ENV') || 'not set'}`)
const currentUrl = await desktop.getCurrentURL()
console.log(` Current URL: ${currentUrl}`)
const windowBounds = await desktop.getWindowBounds()
console.log(` Window size: ${windowBounds.width}x${windowBounds.height}`)
// Example 8: Export to PDF
console.log('π Exporting to PDF...')
await desktop.exportToPDF({
path: './example-export.pdf',
format: 'A4'
})
console.log('β
PDF exported to example-export.pdf')
console.log('\nπ All examples completed successfully!')
console.log('\nπ Files created:')
console.log(' - example-screenshot.png')
console.log(' - example-data.json')
console.log(' - example-export.pdf')
console.log('\nπ‘ You can now interact with the desktop window!')
console.log(' The window will stay open for you to explore.')
} catch (error) {
console.error('β Error running example:', error)
process.exit(1)
}
}
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\nπ Shutting down gracefully...')
process.exit(0)
})
// Run the example
main().catch(console.error)