Skip to content

Commit

Permalink
Merge branch 'dev' into 'main'
Browse files Browse the repository at this point in the history
Added improved System control and IPC event handling

See merge request contribute/prompt-dev-env!7
  • Loading branch information
p3nGu1nZz committed Jun 13, 2024
2 parents 1e34677 + 710882c commit 5d87a03
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 23 deletions.
1 change: 1 addition & 0 deletions gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"prepublish":"echo WARN: : TODO: implement logic to mirror source code from gitlab onto github for distribution.",
"publish": "electron-forge publish"
},
"devDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions gui/src/main/BaseComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// src/main/BaseComponent.js
class BaseComponent {
constructor() {
// Common properties of components can be initialized here
}

// Common methods shared by all components
initialize() {
// Initialization code common to all components
}
}

module.exports = BaseComponent;
17 changes: 17 additions & 0 deletions gui/src/main/BaseSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// src/main/BaseSystem.js
class BaseSystem {
constructor(name) {
this.name = name;
console.log(`[${this.name}] System created`);
}

initialize() {
// Initialization code common to all systems
}

log(message) {
console.log(`[${this.name}] ${message}`);
}
}

module.exports = BaseSystem;
16 changes: 16 additions & 0 deletions gui/src/main/EventComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// src/main/EventComponent.js
const BaseComponent = require('./BaseComponent');

class EventComponent extends BaseComponent {
constructor(type, data) {
super();
this.type = type;
this.data = data;
}

dispatch(ipcMain) {
ipcMain.emit(this.type, this.data);
}
}

module.exports = EventComponent;
9 changes: 5 additions & 4 deletions gui/src/main/EventSystem.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// src/main/EventSystem.js
const { ipcMain } = require('electron');
const BaseSystem = require('./BaseSystem');

class EventSystem {
class EventSystem extends BaseSystem {
constructor() {
console.log("[EVENT-SYSTEM] created");
super('EVENT-SYSTEM');
this.initializeIpcListeners();
}

initializeIpcListeners() {
ipcMain.on('renderer-event', (event, arg) => {
console.log('[EVENT-SYSTEM] Received message from renderer:', arg);
this.log('Received message from renderer: ' + arg);
event.reply('main-event-response', 'Response from main process');
});
}

test() {
console.log('[EVENT-SYSTEM] test function executed');
this.log('test function executed');
}
}

Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
});
15 changes: 15 additions & 0 deletions gui/src/renderer/RendererBaseSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// src/renderer/RendererBaseSystem.js
export default class RendererBaseSystem {
constructor(name) {
this.name = name;
console.log(`[${this.name}] System created`);
}

initialize() {
// Initialization code common to all renderer systems
}

log(message) {
console.log(`[${this.name}] ${message}`);
}
}
30 changes: 16 additions & 14 deletions gui/src/renderer/RendererEventSystem.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// src/renderer/RendererEventSystem.js
export default class RendererEventSystem {
constructor() {
console.log("[R-EVENT-SYSTEM] created");
this.initializeIpcListeners();
}
import RendererBaseSystem from './RendererBaseSystem';

initializeIpcListeners() {
window.api.receive('main-event-response', (data) => {
console.log('[R-EVENT-SYSTEM] Received response from main process:', data);
});
}
export default class RendererEventSystem extends RendererBaseSystem {
constructor() {
super('R-EVENT-SYSTEM');
this.initializeIpcListeners();
}

test() {
console.log('[R-EVENT-SYSTEM] test function executed');
window.api.send('renderer-event', 'Hello to Better Prompts');
}
initializeIpcListeners() {
window.api.receive('main-event-response', (data) => {
this.log('Received response from main process: ' + data);
});
}

test() {
this.log('test function executed');
window.api.send('renderer-event', 'Hello to Better Prompts');
}
}
6 changes: 3 additions & 3 deletions gui/src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<html>
<head>
<meta charset="UTF-8" />
<title>Better Prompt - Tonic AI</title>
<title>Better Prompts - Tonic AI</title>
</head>
<body>
<h1>💖 Better Prompt - Prompt Development Environment</h1>
<p>An innovative platform for crafting, testing, and sharing AI prompts. PDE is where developers, researchers, and AI enthusiasts converge to push the boundaries of conversational AI.</p>
<h1>💖 Better Prompts - An Integrated Prompt Development Environment</h1>
<p>An open and innovative free platform for crafting, testing, and sharing AI prompts. Better Prompts IPDE is where developers, researchers, and AI enthusiasts converge to push the boundaries of conversational AI.</p>
</body>
</html>
2 changes: 1 addition & 1 deletion gui/src/renderer/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// renderer.js
// src/renderer/renderer.js
import './index.css';
import RendererEventSystem from './RendererEventSystem';

Expand Down

0 comments on commit 5d87a03

Please sign in to comment.