Skip to content

Implement toolbox element in the launcher application #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion public/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,30 @@ body, html {
width: calc(var(--tile-width) * 4 + var(--tile-margin) * 3);
height: calc(var(--tile-height) * 4 + var(--tile-margin) * 3);
line-height: calc(var(--tile-height) * 4 + var(--tile-margin) * 3);
}
}

/* Toolbox window */
#toolbox {
position: fixed;
top: 20%;
bottom: 12%;
right: 98px;
background-color: rgba(255, 255, 255, 0.9);
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
overflow: hidden;
z-index: 1000;
}

/* Toolbox modes */
#toolbox.panel {
width: 96px;
}

#toolbox.default {
width: 480px;
}

#toolbox.extended {
width: 860px;
}
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</head>
<body>
<h1>Test</h1>
<div id="toolbox"></div>
</body>
<!--

Expand Down
42 changes: 42 additions & 0 deletions public/js/toolbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Toolbox {
constructor() {
this.window = document.getElementById('toolbox');
this.mode = 'default';
}

show() {
this.window.style.display = 'block';
}

hide() {
this.window.style.display = 'none';
}

setMode(mode) {
this.window.classList.remove('panel', 'default', 'extended');
this.window.classList.add(mode);
this.mode = mode;
}

toggleMode() {
const modes = ['panel', 'default', 'extended'];
const currentIndex = modes.indexOf(this.mode);
const nextIndex = (currentIndex + 1) % modes.length;
this.setMode(modes[nextIndex]);
}

registerGlobalShortcut() {
document.addEventListener('keydown', (event) => {
if (event.key === 'c' && event.shiftKey && (event.metaKey || event.ctrlKey)) {
if (this.window.style.display === 'none' || this.window.style.display === '') {
this.show();
} else {
this.hide();
}
}
});
}
}

const toolbox = new Toolbox();
toolbox.registerGlobalShortcut();
59 changes: 59 additions & 0 deletions src/components/toolbox/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const EventEmitter = require('eventemitter2');
const { BrowserWindow, globalShortcut } = require('electron');

class Toolbox extends EventEmitter {
constructor() {
super();
this.tools = [];
this.window = null;
this.mode = 'default';
}

register(tool) {
Expand All @@ -24,6 +27,62 @@ class Toolbox extends EventEmitter {
toggle() {
this.emit('toolbox-toggled');
}

show() {
if (!this.window) {
this.createWindow();
}
this.window.show();
}

hide() {
if (this.window) {
this.window.hide();
}
}

setMode(mode) {
this.mode = mode;
if (this.window) {
this.window.webContents.send('set-mode', mode);
}
}

toggleMode() {
const modes = ['panel', 'default', 'extended'];
const currentIndex = modes.indexOf(this.mode);
const nextIndex = (currentIndex + 1) % modes.length;
this.setMode(modes[nextIndex]);
}

registerGlobalShortcut() {
globalShortcut.register('CommandOrControl+Shift+C', () => {
if (this.window && this.window.isVisible()) {
this.hide();
} else {
this.show();
}
});
}

createWindow() {
this.window = new BrowserWindow({
width: 480,
height: 600,
frame: false,
transparent: true,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});

this.window.loadURL(`file://${__dirname}/../../public/index.html`);
this.window.on('closed', () => {
this.window = null;
});
}
}

// Singleton
Expand Down
7 changes: 7 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const socketIO = require("socket.io-client");
// Test
const socket = socketIO.connect("http://138.124.180.38:8000");

// Import the toolbox module
const toolbox = require('./components/toolbox');

// Global variables
var contextTree;
var sessionTree;
Expand Down Expand Up @@ -124,6 +127,10 @@ app.on("ready", async () => {
createTray();
});
});

// Create the toolbox window when the app is ready
toolbox.createWindow();
toolbox.registerGlobalShortcut();
});

// MacOS support was blatantly ignored for now
Expand Down