first commit
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Start Generation Here
|
||||
dist/
|
||||
# End Generation Here
|
||||
# Start Generation Here
|
||||
node_modules/
|
||||
# End Generation Here
|
||||
23
index.html
Normal file
23
index.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'"
|
||||
/>
|
||||
<meta
|
||||
http-equiv="X-Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'"
|
||||
/>
|
||||
<title>Hello from Electron renderer!</title>
|
||||
</head>
|
||||
<body>
|
||||
<iframe
|
||||
src="https://devcpone.aplikasi.web.id/one-ui/test/vuex/cpone-antrian/"
|
||||
width="100%"
|
||||
height="500px"
|
||||
></iframe>
|
||||
</body>
|
||||
</html>
|
||||
130
main.js
Normal file
130
main.js
Normal file
@@ -0,0 +1,130 @@
|
||||
const { app, BrowserWindow, session } = require('electron/main')
|
||||
const WebSocket = require('ws')
|
||||
const path = require('path')
|
||||
|
||||
// Variabel global untuk menyimpan domain
|
||||
let userDomain = '';
|
||||
let wsPort = '9099';
|
||||
let mainWindow = null;
|
||||
|
||||
const createSetupWindow = () => {
|
||||
const setupWindow = new BrowserWindow({
|
||||
width: 400,
|
||||
height: 300,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false
|
||||
}
|
||||
});
|
||||
|
||||
setupWindow.loadFile('setup.html');
|
||||
|
||||
// Terima domain dari window setup
|
||||
const { ipcMain } = require('electron');
|
||||
ipcMain.on('submit-domain', (event, domain, port) => {
|
||||
userDomain = domain;
|
||||
wsPort = port || '9099';
|
||||
setupWindow.close();
|
||||
|
||||
// Buat window utama setelah mendapat domain
|
||||
createMainWindow();
|
||||
});
|
||||
}
|
||||
|
||||
const createMainWindow = () => {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
autoplayPolicy: 'no-user-gesture-required',
|
||||
webSecurity: false,
|
||||
nodeIntegration: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
contextIsolation: false,
|
||||
allowRunningInsecureContent: true
|
||||
}
|
||||
})
|
||||
|
||||
mainWindow.webContents.session.setPermissionRequestHandler((webContents, permission, callback) => {
|
||||
if (permission === 'media') {
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Set CSP dengan domain yang sudah diinput
|
||||
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
'Content-Security-Policy': [`default-src 'self' 'unsafe-inline' 'unsafe-eval' https://${userDomain} wss://${userDomain}:${wsPort} ws://${userDomain}:${wsPort}`]
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
'Content-Security-Policy': [`default-src 'self' 'unsafe-inline' 'unsafe-eval' https://${userDomain} wss://${userDomain}:${wsPort} ws://${userDomain}:${wsPort}`]
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
mainWindow.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
callback({
|
||||
requestHeaders: {
|
||||
...details.requestHeaders,
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Load URL dengan domain yang sudah diinput
|
||||
mainWindow.loadURL(`https://${userDomain}/one-ui/test/vuex/cpone-antrian/`);
|
||||
|
||||
// Inisialisasi WebSocket setelah window utama dibuat
|
||||
connectWebSocket();
|
||||
}
|
||||
|
||||
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||
event.preventDefault();
|
||||
callback(true);
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createSetupWindow() // Mulai dengan window setup terlebih dahulu
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createSetupWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
function connectWebSocket() {
|
||||
try {
|
||||
ws = new WebSocket(`wss://${userDomain}:${wsPort}/`);
|
||||
|
||||
ws.addEventListener('open', (event) => {
|
||||
console.log('WebSocket Connected');
|
||||
});
|
||||
|
||||
ws.addEventListener('error', (error) => {
|
||||
console.error('WebSocket Error:', error);
|
||||
});
|
||||
|
||||
ws.addEventListener('close', (event) => {
|
||||
console.log('WebSocket Closed:', event.code, event.reason);
|
||||
setTimeout(connectWebSocket, 5000);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating WebSocket:', error);
|
||||
setTimeout(connectWebSocket, 5000);
|
||||
}
|
||||
}
|
||||
3748
package-lock.json
generated
Normal file
3748
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
Normal file
23
package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "queue-display-sampling",
|
||||
"version": "1.0.0",
|
||||
"description": "queue display sampling",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"build": "electron-builder",
|
||||
"build:win": "electron-builder --win",
|
||||
"build:mac": "electron-builder --mac",
|
||||
"build:linux": "electron-builder --linux"
|
||||
},
|
||||
"author": "sas",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"electron": "^34.1.1",
|
||||
"electron-builder": "^24.13.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-updater": "^6.1.7",
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
}
|
||||
63
setup.html
Normal file
63
setup.html
Normal file
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Setup Domain</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
background-color: #4caf50;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="form-group">
|
||||
<label for="domain">Domain (tanpa https://)</label>
|
||||
<input
|
||||
type="text"
|
||||
id="domain"
|
||||
placeholder="Contoh: devcpone.aplikasi.web.id"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="port">Port WebSocket</label>
|
||||
<input type="text" id="port" value="9099" />
|
||||
</div>
|
||||
<button onclick="submitDomain()">Simpan</button>
|
||||
|
||||
<script>
|
||||
const { ipcRenderer } = require("electron");
|
||||
|
||||
function submitDomain() {
|
||||
const domain = document.getElementById("domain").value;
|
||||
const port = document.getElementById("port").value;
|
||||
if (domain) {
|
||||
ipcRenderer.send("submit-domain", domain, port);
|
||||
} else {
|
||||
alert("Mohon masukkan domain");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user