-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathclose-example.mjs
More file actions
82 lines (72 loc) · 1.97 KB
/
Copy pathclose-example.mjs
File metadata and controls
82 lines (72 loc) · 1.97 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
import { Application } from '../index.js';
const app = new Application();
// Create a browser window with a webview
const browserWindow = app.createBrowserWindow({
title: 'Close Example',
width: 800,
height: 600,
});
const _webview = browserWindow.createWebview({
html: `
<!DOCTYPE html>
<html>
<head>
<title>Close Example</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
display: flex;
flex-direction: column;
gap: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Close Example</h1>
<p>This example demonstrates how to close the application gracefully.</p>
<button onclick="closeApp()">Close Application</button>
<button onclick="reloadWebview()">Reload Webview</button>
<script>
function closeApp() {
// This will trigger the ApplicationCloseRequested event
// and clean up all resources including temp folders
window.close();
}
function reloadWebview() {
// This will reload the webview
location.reload();
}
</script>
</body>
</html>
`,
});
app.on('window-close-requested', () => {
console.log('Window close requested');
});
app.on('application-close-requested', () => {
console.log('Application close requested');
});
// Example: Programmatically close the application after 5 seconds
// setTimeout(() => {
// console.log('Closing application programmatically...');
// app.exit();
// }, 5000);
// Example: Programmatically hide the window
// setTimeout(() => {
// console.log('Hiding window...');
// browserWindow.hide();
// }, 3000);
// Example: Programmatically show the window
// setTimeout(() => {
// console.log('Showing window...');
// browserWindow.show();
// }, 4000);
// Run the application
await app.run();