mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-06 04:01:51 +08:00
141 lines
3.9 KiB
HTML
141 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8"/>
|
|
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
|
<title>Single Instance Demo</title>
|
|
<script src="/wails/runtime.js" type="module"></script>
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
margin: 0;
|
|
padding: 20px;
|
|
background-color: #f0f0f0;
|
|
color: #333;
|
|
}
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
h1 {
|
|
color: #2c5282;
|
|
margin-bottom: 20px;
|
|
}
|
|
.info-box {
|
|
background-color: #f8f9fa;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 4px;
|
|
padding: 15px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.info-box h2 {
|
|
margin-top: 0;
|
|
color: #4a5568;
|
|
font-size: 1.2em;
|
|
}
|
|
.info-item {
|
|
margin: 10px 0;
|
|
}
|
|
.info-label {
|
|
font-weight: bold;
|
|
color: #4a5568;
|
|
}
|
|
.args-list {
|
|
margin: 5px 0;
|
|
padding-left: 20px;
|
|
}
|
|
.args-list li {
|
|
word-break: break-all;
|
|
margin: 3px 0;
|
|
}
|
|
.instructions {
|
|
background-color: #ebf8ff;
|
|
border: 1px solid #bee3f8;
|
|
border-radius: 4px;
|
|
padding: 15px;
|
|
margin-top: 20px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Single Instance Demo</h1>
|
|
|
|
<div class="info-box">
|
|
<h2>Current Instance Information</h2>
|
|
<div id="instanceInfo">Loading...</div>
|
|
</div>
|
|
|
|
<div class="instructions">
|
|
<h2>Instructions</h2>
|
|
<p>Try launching another instance of this application. The first instance will:</p>
|
|
<ul>
|
|
<li>Receive notification of the second instance launch</li>
|
|
<li>Get the command line arguments of the second instance</li>
|
|
<li>Get the working directory of the second instance</li>
|
|
<li>Receive any additional data passed from the second instance</li>
|
|
</ul>
|
|
<p>Check the application logs to see the information received from second instances.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
let lastNotificationTime = "";
|
|
|
|
function init() {
|
|
updateInstanceInfo();
|
|
// Listen for second instance launch
|
|
wails.Events.On('secondInstanceLaunched', (info) => {
|
|
console.log('Second instance launched');
|
|
lastNotificationTime = new Date().toLocaleString();
|
|
debugger;
|
|
updateInstanceInfo(info.data[0]);
|
|
})
|
|
}
|
|
|
|
// Update instance information
|
|
async function updateInstanceInfo(info) {
|
|
if (!info) {
|
|
info = await wails.Call.ByName('main.App.GetCurrentInstanceInfo');
|
|
}
|
|
const infoDiv = document.getElementById('instanceInfo');
|
|
infoDiv.innerHTML = '';
|
|
if (lastNotificationTime) {
|
|
infoDiv.innerHTML += `<div class="info-item">
|
|
<span class="info-label">Second Instance Launch Time:</span> ${lastNotificationTime}
|
|
</div>`
|
|
}
|
|
infoDiv.innerHTML += `
|
|
<div class="info-item">
|
|
<span class="info-label">Arguments:</span>
|
|
<ul class="args-list">
|
|
${info.args.map(arg => `<li>${arg}</li>`).join('')}
|
|
</ul>
|
|
</div>
|
|
<div class="info-item">
|
|
<span class="info-label">Working Directory:</span> ${info.workingDir}
|
|
</div>
|
|
`;
|
|
|
|
if (info.additionalData) {
|
|
infoDiv.innerHTML += `
|
|
<div class="info-item">
|
|
<span class="info-label">Additional Data:</span>
|
|
<ul class="args-list">
|
|
${Object.entries(info.additionalData).map(([key, value]) => `<li>${key}: ${value}</li>`).join('')}
|
|
</ul>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
// Update info when page loads
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
</script>
|
|
</body>
|
|
</html> |