Skip to content

Commit 6409369

Browse files
committed
ipcChannel implemented. Splashscreen module and random fixes
1 parent bc9f1ff commit 6409369

File tree

11 files changed

+117
-43
lines changed

11 files changed

+117
-43
lines changed

config.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
{
8383
"enabled": true,
8484
"extension": "keys-checker",
85-
"custom_id": false
85+
"custom_id": false,
86+
"structure_id": [1,2,3,4]
8687
},
8788
"autostart":
8889
{
@@ -103,7 +104,13 @@
103104
"splashscreen":
104105
{
105106
"enabled": true,
106-
"extension": "splashscreen"
107+
"extension": "splashscreen",
108+
"splash_timeout": 20,
109+
"splash_url":
110+
{
111+
"pathname": "google.com",
112+
"protocol": "https"
113+
}
107114
}
108115
}
109116
}

extensions/autoupdate/main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const { autoUpdater } = require('electron-updater');
33
const path = require('../../lib/path2');
44
const { HOME_BIN_LINUX } = require('../../lib/Constants');
55
const fs = require('fs');
6+
const ipcChannel = require('../../lib/icpChannel');
7+
const Env = require('../../env');
68

79

810
// WARNING: THIS SCRIPT WILL CHANGE THE MACHINE'S STARTUP BEHAVIOUR.
@@ -18,6 +20,7 @@ class Autoupdater extends require('../../lib/BaseModule')
1820

1921
setup_linux()
2022
{
23+
2124
this.updateFunction = function() {
2225
this.EXECUTABLE_NAME = app.app_info.app_executable;
2326
this.DOWNLOAD_PATH = app.getPath("downloads");
@@ -49,12 +52,12 @@ class Autoupdater extends require('../../lib/BaseModule')
4952
this.warn("User refused to update");
5053
});
5154
});
52-
53-
autoUpdater.on('download-progress', progressObj => {
54-
const logMsg = `Download speed: ${progressObj.bytesPerSecond} - ${progressObj.percent.toFixed(2)}%`;
55-
this.log(logMsg);
56-
this.window.setTitle(`Downloading update... ${progressObj.percent.toFixed(0)}%`);
57-
});
55+
if (Env.VERBOSE)
56+
autoUpdater.on('download-progress', progressObj => {
57+
const logMsg = `Download speed: ${progressObj.bytesPerSecond} - ${progressObj.percent.toFixed(2)}%`;
58+
this.log(logMsg);
59+
this.window.setTitle(`Downloading update... ${progressObj.percent.toFixed(0)}%`);
60+
});
5861

5962
autoUpdater.on('update-downloaded', info => {
6063
// dialog.showMessageBox(this.window, {
@@ -75,6 +78,12 @@ class Autoupdater extends require('../../lib/BaseModule')
7578

7679
autoUpdater.on('update-not-available', () => {
7780
this.log('No updates available.');
81+
dialog.showMessageBox(this.window, {
82+
type: 'info',
83+
title: 'No updated available',
84+
message: ``,
85+
buttons: ['Ok']
86+
})
7887
});
7988

8089
autoUpdater.on('error', err => {
@@ -93,6 +102,7 @@ class Autoupdater extends require('../../lib/BaseModule')
93102
late_setup()
94103
{
95104
this.updateFunction();
105+
ipcChannel.newMainHandler('usr-check-for-updates', () => this.updateFunction());
96106
}
97107
}
98108

extensions/autoupdate/preload.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const ipcChannel = require('../../lib/icpChannel.js');
2+
13
class Autoupdate_preload extends require('../../lib/BasePreload.js')
24
{
35
update_check_timer = null;
@@ -11,12 +13,20 @@ class Autoupdate_preload extends require('../../lib/BasePreload.js')
1113
window.addEventListener('pointerdown', (event) => {
1214
this.update_check_timer = setTimeout(() => {this.updateCheckRequest()}, this.__conf.update_mode.duration * 1000);
1315
})
16+
window.addEventListener('pointerup', (event) => {
17+
if (this.update_check_timer)
18+
{
19+
clearTimeout(this.update_check_timer);
20+
this.update_check_timer = null;
21+
}
22+
});
1423
}
1524
}
1625

1726
updateCheckRequest()
1827
{
1928
this.warn("Update check requested!");
29+
ipcChannel.sendSignalToMain('usr-check-for-updates');
2030
}
2131
}
2232

extensions/keys-checker/main.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const { ipcMain, remote } = require('electron');
1+
const { ipcMain, remote, dialog } = require('electron');
22
const { machineIdSync } = require("node-machine-id");
3+
const ipcChannel = require('../../lib/icpChannel');
34

45
// Sample Module. Plase copy-paste this file into new module's main folder
56
class LocalKeysCheck extends require('../../lib/BaseModule')
@@ -11,7 +12,7 @@ class LocalKeysCheck extends require('../../lib/BaseModule')
1112

1213
setup()
1314
{
14-
ipcMain.handle('get-key', async () => await this.getLocalKey());
15+
ipcChannel.newMainHandler('get-key', async () => await this.getLocalKey());
1516

1617
const id = machineIdSync();
1718
this.real_machine_id = machineIdSync(false);
@@ -26,12 +27,18 @@ class LocalKeysCheck extends require('../../lib/BaseModule')
2627
async getLocalKey()
2728
{
2829
this.log(this.tab.webContents.getURL(), 'is trying to access local keys info');
29-
return {machine_id: this.machine_id, structure_id: [4,5,6,7]};
30+
return {machine_id: this.machine_id, structure_id: this.__conf.structure_id};
3031
}
3132

3233
askStructureId()
3334
{
34-
// const dg = remote.dialog;
35+
if (!this.__conf.structure_id)
36+
dialog.showMessageBox(this.window, {
37+
type: 'info',
38+
title: 'Set structure id',
39+
message: `Please set the app's structure id in ${this.getAppDataDir() + this.MODULE_NAME + '.json'}`,
40+
buttons: ['Ok']
41+
})
3542
}
3643
}
3744

extensions/keys-checker/preload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const { contextBridge, ipcRenderer } = require('electron');
2+
const ipcChannel = require('../../lib/icpChannel.js');
23

34
class TouchUtils_preload extends require('../../lib/BasePreload.js')
45
{
56
getKeyPlease()
67
{
7-
ipcRenderer.invoke('get-key').then(keys => {return keys.machine_id});
8+
ipcChannel.sendSignalToMain('get-key').then(keys => {return keys.machine_id});
89
}
910

1011
setup()

extensions/splashscreen/main.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { WebContentsView } = require('electron');
22
const TabsManager = require('../../lib/TabsManager');
3+
const Env = require('../../env');
4+
const url = require('url');
35

46

57
// Sample Module. Plase copy-paste this file into new module's main folder
@@ -8,6 +10,9 @@ class Splashscreen extends require('../../lib/BaseModule')
810
MODULE_NAME = "splashscreen"; // MUST be the same as the 'extension' field in config.json
911
required_modules = ['window-events'];
1012

13+
is_splashscreen = false;
14+
inputed = true;
15+
1116
setup()
1217
{
1318
this.splash = new WebContentsView({
@@ -16,19 +21,42 @@ class Splashscreen extends require('../../lib/BaseModule')
1621
nodeIntegration: false,
1722
sandbox: false
1823
}});
19-
20-
// this.window.contentView.addChildView(this.splash);
21-
22-
// this.splash.setBounds({x: 0, y: 0 , height: this.window.getContentBounds().height, width: this.window.getContentBounds().width});
2324

24-
// this.splash.webContents.loadURL("https://google.com");
25-
25+
this.splash.webContents.loadURL(url.format(this.__conf.splash_url));
26+
27+
this.tab.webContents.on('input-event', (e, input) => {
28+
this.inputed = true;
29+
});
30+
this.splash.webContents.on('input-event', () => {
31+
if (this.is_splashscreen)
32+
this.removeSplash();
33+
});
34+
35+
setInterval(() => {
36+
if (Env.VERBOSE)
37+
this.log("splash_check");
38+
if (!this.inputed)
39+
this.setSplash();
40+
this.inputed = false;
41+
}, (this.__conf.splash_timeout || 60) * 500);
42+
2643
// const mainTab = TabsManager.activeTabName;
27-
2844
// TabsManager.setNewTab(this.splash, "splash");
29-
3045
// setTimeout(TabsManager.setTab, 5000, mainTab);
3146
}
47+
48+
setSplash()
49+
{
50+
this.splash.setBounds({x: 0, y: 0 , height: this.window.getContentBounds().height, width: this.window.getContentBounds().width});
51+
this.window.contentView.addChildView(this.splash);
52+
setTimeout(() => { this.is_splashscreen = true; }, 500);
53+
}
54+
55+
removeSplash()
56+
{
57+
this.is_splashscreen = false;
58+
this.window.contentView.removeChildView(this.splash);
59+
}
3260
}
3361

3462
module.exports = Splashscreen;

extensions/touch-utils/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { app } = require("electron");
2+
const Env = require("../../env");
23

34
// radial double-click
45
class DoubleClick extends require('../../lib/BaseModule')
@@ -21,7 +22,7 @@ class DoubleClick extends require('../../lib/BaseModule')
2122
setup()
2223
{
2324
this.tab.webContents.on('input-event', (event, input) => {
24-
if (input.type != 'mouseMove')
25+
if (input.type != 'mouseMove' && Env.VERBOSE)
2526
this.log("sending an", input.type);
2627
switch(input.type)
2728
{
@@ -90,7 +91,6 @@ class DoubleClick extends require('../../lib/BaseModule')
9091
});
9192
}
9293

93-
9494
app.commandLine.appendSwitch('touch-events', 'enabled');
9595
// app.commandLine.appendSwitch('enable-pointer-events');
9696
}

extensions/touch-utils/preload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { createMouseEvent, sendMouseEvent } = require('../../lib/utils.js')
33
const fs = require('fs');
44
const path = require('path');
55
const Env = require('../../env.js');
6+
const ipcChannel = require('../../lib/icpChannel.js');
67

78
class TouchUtils_preload extends require('../../lib/BasePreload.js')
89
{
@@ -33,7 +34,7 @@ class TouchUtils_preload extends require('../../lib/BasePreload.js')
3334
});
3435

3536
// radial double-click signal forward
36-
ipcRenderer.on('double-click2', function (e, pos)
37+
ipcChannel.newRendererHandler('double-click2', (e, pos) =>
3738
{
3839
var dbc_event = e;
3940
dbc_event.target = this.lastTouchedObject;

extensions/window-events/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class WindowSetup extends require('../../lib/BaseModule')
3434
globalShortcut.register('ctrl+d', () => {
3535
this.tab.webContents.toggleDevTools();
3636
});
37-
globalShortcut.register('ctrl+c', () => {
37+
globalShortcut.register('ctrl+x', () => {
3838
checkActiveModules();
3939
});
4040
globalShortcut.register('ctrl+w', () => {

lib/icpChannel.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,39 @@ const { ipcRenderer, ipcMain } = require('electron')
22

33
class ipcChannel
44
{
5-
static newMainHandler(method_name, callback)
6-
{
5+
static methods_list_main = [];
6+
static methods_list_rend = [];
7+
8+
static newMainHandler(method_name, callback)
9+
{
710
ipcMain.handle(method_name, callback);
8-
}
11+
this.methods_list_main.push(method_name);
12+
}
913

10-
static newRendererHandler(method_name, callback)
11-
{
14+
static newRendererHandler(method_name, callback)
15+
{
1216
ipcRenderer.on(method_name, callback);
13-
}
17+
this.methods_list_rend.push(method_name);
18+
}
1419

15-
static sendSignalToRender(method, tab, contents)
16-
{
17-
tab.send(method, contents);
18-
}
20+
static sendSignalToRender(method, tab, contents)
21+
{
22+
// if (!this.methods_list_rend.find((s) => s == method))
23+
// console.log("Method not registered!!");
24+
tab.send(method, contents);
25+
}
1926

20-
static sendSignalToMain(method, contents)
21-
{
22-
return ipcRenderer.invoke(method, contents);
23-
}
27+
static sendSignalToMain(method, contents)
28+
{
29+
// if (!this.methods_list_main.find((s) => s == method))
30+
// console.log("Method not registered!!");
31+
return ipcRenderer.invoke(method, contents);
32+
}
2433

25-
static async sendSignalToMainSync(method, contents)
26-
{
27-
return await ipcRenderer.invoke(method, contents);
28-
}
34+
static async sendSignalToMainSync(method, contents)
35+
{
36+
return await ipcRenderer.invoke(method, contents);
37+
}
2938
}
3039

3140
module.exports = ipcChannel;

0 commit comments

Comments
 (0)