Skip to content

Commit

Permalink
Temporary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
devknight216 committed Mar 20, 2024
1 parent 27b89e3 commit e309f9d
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"ffprobe-static": "^3.1.0",
"fluent-ffmpeg": "^2.1.2",
"form-data": "^4.0.0",
"iohook2": "^1.0.6",
"lodash": "^4.17.21",
"node-polyfill-webpack-plugin": "^2.0.1",
"os": "^0.1.2",
Expand Down
45 changes: 45 additions & 0 deletions public/overlay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>Overlay</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
color: white;
text-align: center;
}

#overlay {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0);
opacity: 0.1;
padding: 10px;
border-radius: 5px;
z-index: 9999;
}
</style>
</head>
<body>
<div id="overlay"></div>

<script>
const { ipcRenderer } = require('electron');

ipcRenderer.on('showOverlay', (event, text) => {
const overlay = document.getElementById('overlay');
const textElement = document.createElement('div');
textElement.textContent = text;
overlay.appendChild(textElement);
setTimeout(() => {
textElement.remove(); // Remove the text after 1 second
}, 1000);
});
</script>

</body>
</html>
49 changes: 49 additions & 0 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,13 @@ export default {
this.sources = data;
if (this.viewMode === "normal") {
console.log("1");
this.sourcePickerDialog = true;
} else {
console.log("3");
if (this.$isElectron) {
console.log("88");
await this.$electronService.openSourcePickerWindow(this.sources);
}
}
Expand Down Expand Up @@ -1473,6 +1477,45 @@ export default {
}
},
async videoRecordProcess() {
const handleKeyPress = (event) => {
let eventText = "";
if (event.ctrlKey) {
eventText += "Ctrl + ";
}
if (event.altKey) {
eventText += "Alt + ";
}
if (event.shiftKey) {
eventText += "Shift + ";
}
eventText += event.key.toUpperCase();
// Show the text overlay
showTextOverlay(eventText);
};
const handleMouseClick = () => {
// Show the text overlay for mouse click
showTextOverlay("Mouse Click");
};
const showTextOverlay = (text) => {
const textOverlay = document.createElement("div");
textOverlay.textContent = text;
textOverlay.style.position = "fixed";
textOverlay.style.top = "50%";
textOverlay.style.left = "50%";
textOverlay.style.transform = "translate(-50%, -50%)";
textOverlay.style.background = "rgba(0, 0, 0, 0.5)";
textOverlay.style.color = "white";
textOverlay.style.padding = "10px";
textOverlay.style.borderRadius = "5px";
textOverlay.style.zIndex = "9999";
document.body.appendChild(textOverlay);
setTimeout(() => {
textOverlay.remove();
}, 1000); // Remove after 1 second
};
this.handleStream = (stream) => {
if (this.config.audioCapture && this.audioDevices.length > 0) {
stream.addTrack(dest.stream.getAudioTracks()[0]);
Expand All @@ -1487,6 +1530,9 @@ export default {
let poster;
let frames = [];
mediaRecorder.onstart = () => {
document.addEventListener("click", handleMouseClick);
document.addEventListener("keydown", handleKeyPress);
// this.$electronService.startKeyboardCapture();
this.recordVideoStarted = true;
const video = document.createElement("video");
video.srcObject = stream;
Expand Down Expand Up @@ -1521,6 +1567,9 @@ export default {
}
};
mediaRecorder.onstop = async () => {
// this.$electronService.stopKeyboardCapture();
document.removeEventListener("click", handleMouseClick);
document.removeEventListener("keydown", handleKeyPress);
this.recordVideoStarted = false;
const blob = new Blob(frames, { type: mimeType });
const buffer = await blob.arrayBuffer();
Expand Down
5 changes: 4 additions & 1 deletion src/components/dialogs/AddEvidenceDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ export default {
},
mounted() {
this.getAllTags();
console.log("78787evidencedialog");
if (this.$isElectron) {
// this.$electronService.onActiveSession(this.activeSession);
// this.activeSession();
Expand Down Expand Up @@ -506,18 +507,20 @@ export default {
this.allTags = [...new Set([...defaultTagTexts, ...sessionTagTexts])];
},
async activeSession() {
console.log("89898activeSession");
// set theme mode
const isDarkMode = this.config.apperance === "dark";
this.$vuetify.theme.dark = isDarkMode;
localStorage.setItem("isDarkMode", isDarkMode);
this.item = { ...this.itemData };
console.log("465373", this.item);
const splitName = this.item?.fileName.split(".") || [""];
this.name = splitName.slice(0, -1).join(".");
// optimize video
if (this.item.fileType === "video") {
console.log("1111111 optimize started");
await this.optimizeVideo();
} else {
this.processing = false;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/IpcHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ ipcMain.handle(IPC_HANDLERS.CAPTURE, async (event, args) => {

ipcMain.handle(IPC_HANDLERS.WINDOW, async (event, args) => {
switch (args.func) {
case IPC_FUNCTIONS.START_KEYBOARD_CAPTURE:
console.log("666");
return windowUtility.startKeyboardCapture();
case IPC_FUNCTIONS.STOP_KEYBOARD_CAPTURE:
console.log("222");
return windowUtility.stopKeyboardCapture();
case IPC_FUNCTIONS.SET_DEV_MODE:
return windowUtility.setDevMode(args.data);
case IPC_FUNCTIONS.OPEN_ADD_WINDOW:
Expand Down
55 changes: 53 additions & 2 deletions src/modules/WindowUtility.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { app, BrowserWindow, screen } = require("electron");
const { app, BrowserWindow, screen, ipcMain } = require("electron");
const iohook = require("iohook2");

let isDevelopment = process.env.NODE_ENV !== "production";

Expand All @@ -8,11 +9,61 @@ const browserUtility = require("./BrowserWindowUtility");
const path = require("path");

const { VIEW_MODE, IPC_BIND_KEYS } = require("./constants");
let overlayWindow;
function createOverlayWindow() {
overlayWindow = new BrowserWindow({
width: 400,
height: 200,
transparent: true,
frame: false,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true
}
});

overlayWindow.setIgnoreMouseEvents(true);

overlayWindow.loadURL("app://./overlay.html");
// "app://./index.html"

overlayWindow.on('closed', () => {
overlayWindow = null;
});
}

module.exports.setDevMode = async ({ enabled }) => {
isDevelopment = enabled;
};

module.exports.startKeyboardCapture = () => {
ipcMain.on('overlayShown', () => {
// After 1 second, send a message to hide the overlay
setTimeout(() => {
overlayWindow.webContents.send('hideOverlay');
}, 1000);
});
createOverlayWindow();
iohook.on("keydown", event => {
console.log("Key pressed:", event);
overlayWindow.webContents.send("showOverlay", event.key);
// Handle the event as needed
});

// Start listening for mouse events
iohook.on("mousedown", event => {
console.log("Mouse clicked:", event);
overlayWindow.webContents.send("showOverlay", "Mouse Click");
// Handle the event as needed
});
iohook.start();
};

module.exports.stopKeyboardCapture = () => {
console.log("123 Stop!");
iohook.stop();
};

module.exports.getMainWindow = () => {
const win = new BrowserWindow({
width: 800,
Expand Down Expand Up @@ -275,12 +326,12 @@ module.exports.setWindowSize = ({ width, height }) => {
};

module.exports.openModalWindow = (data) => {
console.log("999");
const parentWindow = browserUtility.getParentWindow();
const url =
process.env.NODE_ENV === "development"
? `http://localhost:8080/#/${data.path}`
: `file://${__dirname}/index.html#${data.path}`;

if (!modalWin) {
modalWin = new BrowserWindow({
width: data.size.width,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const IPC_HANDLERS = {
};

export const IPC_FUNCTIONS = {
START_KEYBOARD_CAPTURE: "startKeyboardCapture",
STOP_KEYBOARD_CAPTURE: "stopKeyboardCapture",
GET_SYSTEM_INFO: "getSystemInfo",
GET_MEDIA_SOURCE: "getMediaSource",
SAVE_NOTE: "saveNote",
Expand Down
45 changes: 45 additions & 0 deletions src/modules/overlay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>Overlay</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
color: white;
text-align: center;
}

#overlay {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0, 0, 0, 0);
opacity: 0.1;
padding: 10px;
border-radius: 5px;
z-index: 9999;
}
</style>
</head>
<body>
<div id="overlay"></div>

<script>
const { ipcRenderer } = require('electron');

ipcRenderer.on('showOverlay', (event, text) => {
const overlay = document.getElementById('overlay');
const textElement = document.createElement('div');
textElement.textContent = text;
overlay.appendChild(textElement);
setTimeout(() => {
textElement.remove(); // Remove the text after 1 second
}, 1000);
});
</script>

</body>
</html>
14 changes: 14 additions & 0 deletions src/services/electronService.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ export default class ElectronService {
});
}

async startKeyboardCapture() {
return await window.ipc.invoke(IPC_HANDLERS.WINDOW, {
func: IPC_FUNCTIONS.START_KEYBOARD_CAPTURE,
});
}

stopKeyboardCapture() {
console.log("333");
return window.ipc.invoke(IPC_HANDLERS.WINDOW, {
func: IPC_FUNCTIONS.STOP_KEYBOARD_CAPTURE,
});
}

async openAddWindow(data) {
await window.ipc.invoke(IPC_HANDLERS.WINDOW, {
func: IPC_FUNCTIONS.OPEN_ADD_WINDOW,
Expand Down Expand Up @@ -135,6 +148,7 @@ export default class ElectronService {
}

async openSourcePickerWindow(sources) {
console.log("0123");
return await window.ipc.invoke(IPC_HANDLERS.WINDOW, {
func: IPC_FUNCTIONS.OPEN_MODAL_WINDOW,
data: {
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3516,7 +3516,7 @@ bind-event-listener@^2.1.1:
resolved "https://registry.npmjs.org/bind-event-listener/-/bind-event-listener-2.1.1.tgz"
integrity sha512-O+a5c0D2se/u2VlBJmPRn45IB6R4mYMh1ok3dWxrIZ2pmLqzggBhb875mbq73508ylzofc0+hT9W41x4Y2s8lg==

bindings@^1.5.0:
bindings@^1.2.1, bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
Expand Down Expand Up @@ -7308,6 +7308,14 @@ interpret@^1.0.0:
resolved "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==

iohook2@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/iohook2/-/iohook2-1.0.6.tgz#1460b7f6f6b8552ddd4f1a1cf5936833b170440b"
integrity sha512-fZuMADzz9uDof/SgmVt0XeH8uYYRPowAto+8m7NiBcp12IJub78HcyqcMoEVyTGFLzoS8p1AcBFJTS9l5Yb8eQ==
dependencies:
bindings "^1.2.1"
nan "^2.4.0"

ip-regex@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz"
Expand Down Expand Up @@ -9077,6 +9085,11 @@ nan@^2.12.1, nan@^2.17.0:
resolved "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz"
integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==

nan@^2.4.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.19.0.tgz#bb58122ad55a6c5bc973303908d5b16cfdd5a8c0"
integrity sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw==

nanoid@^3.3.6:
version "3.3.6"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz"
Expand Down

0 comments on commit e309f9d

Please sign in to comment.