Skip to content

Commit 8ab216e

Browse files
committed
lots
1 parent fcaab81 commit 8ab216e

File tree

26 files changed

+435
-188
lines changed

26 files changed

+435
-188
lines changed

config_files/browser_with_tabs.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "Leonardo Pollini",
77
"email": "[email protected]"
88
},
9-
"version": "0.0.21",
9+
"version": "0.0.23",
1010
"autoupdate": false,
1111
"electron_package": "package.json",
1212
"app_name": "Webpage Accessor",
@@ -71,6 +71,16 @@
7171
"enabled": true,
7272
"actions":
7373
{
74+
"webpage_filter":
75+
{
76+
"enabled": true,
77+
"hosts_whitelist": [],
78+
"hosts_blacklist": [],
79+
"webpages_whitelist": [],
80+
"webpages_blacklist": [],
81+
"allow_navigation": true,
82+
"extension": "webpage-filter"
83+
},
7484
"toolbar":
7585
{
7686
"enabled": true,
@@ -81,10 +91,9 @@
8191
"allow_target_blank": true,
8292
"default_url":
8393
{
84-
"pathname": "new_page.html",
85-
"protocol": "file"
86-
},
87-
"create_on_open": true
94+
"pathname": "pms.parchotels.dev",
95+
"protocol": "https"
96+
}
8897
},
8998
"electron-api":
9099
{

extensions/electronAPI/main.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ class ElectronAPI extends require('../../lib/BaseModule')
1010
// constructor(window, tab) { super(window, tab); }
1111

1212
// Setup code here. This function is called in BaseModule's constructor.
13-
setup()
14-
{
15-
ipcMain.handle('select-file', async () => await this.selectFile());
16-
ipcMain.handle('read-file', async (event, path) => await this.readFile(path));
17-
// ipcMain.handle('get-key', async () => await this.getLocalKey()); --> moved in keys-checker.js
18-
}
13+
// setup()
14+
// {
15+
// ipcMain.handle('select-file', async () => await this.selectFile());
16+
// ipcMain.handle('read-file', async (event, path) => await this.readFile(path));
17+
// // ipcMain.handle('get-key', async () => await this.getLocalKey()); --> moved in keys-checker.js
18+
// }
1919

20-
async readFile(path)
21-
{
22-
console.log("reading file");
23-
try {
24-
return fs.readFileSync(path, 'utf-8');
25-
} catch (err) {
26-
console.error(err);
27-
return null;
28-
}
29-
}
20+
// async readFile(path)
21+
// {
22+
// console.log("reading file");
23+
// try {
24+
// return fs.readFileSync(path, 'utf-8');
25+
// } catch (err) {
26+
// console.error(err);
27+
// return null;
28+
// }
29+
// }
3030

3131
}
3232

extensions/keys-checker/main.js

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

56
// Sample Module. Plase copy-paste this file into new module's main folder
67
class LocalKeysCheck extends require('../../lib/BaseModule')
78
{
8-
MODULE_NAME = "keys-checker";
9-
machine_id = null;
10-
real_machine_id;
11-
12-
13-
setup()
14-
{
15-
ipcChannel.newMainHandler('get-key', async () => await this.getLocalKey());
16-
17-
const id = machineIdSync();
18-
this.real_machine_id = machineIdSync(false);
19-
20-
this.machine_id = this.__conf.custom_id || id;
21-
22-
this.log('Loaded local id:', this.machine_id);
23-
24-
this.askStructureId();
25-
}
26-
27-
async getLocalKey()
9+
MODULE_NAME = "keys-checker";
10+
machine_id = null;
11+
real_machine_id;
12+
13+
14+
setup()
15+
{
16+
ipcChannel.newMainHandler('get-info', async () => await this.getInfo());
17+
18+
const id = machineIdSync();
19+
this.real_machine_id = machineIdSync(false);
20+
21+
this.machine_id = this.__conf.custom_id || id;
22+
23+
this.log('Loaded local id:', this.machine_id);
24+
25+
this.warn('ip addressen:', this.getIpAddr());
26+
27+
this.askStructureId();
28+
}
29+
30+
async getInfo()
2831
{
29-
this.log(this.tab.webContents.getURL(), 'is trying to access local keys info');
30-
return {machine_id: this.machine_id, structure_id: this.__conf.structure_id};
32+
this.log(this.tab.webContents.getURL(), 'is trying to access local keys info');
33+
return {machine_id: this.machine_id, structure_id: this.__conf.structure_id, ip_address: this.getIpAddr()};
3134
}
3235

33-
askStructureId()
34-
{
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-
})
42-
}
36+
getIpAddr()
37+
{
38+
const ifaces = os.networkInterfaces();
39+
let ipAdresse = {};
40+
Object.keys(ifaces).forEach(function (ifname) {
41+
let alias = 0;
42+
ifaces[ifname].forEach(function (iface) {
43+
if ('IPv4' !== iface.family || iface.internal !== false) {
44+
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
45+
return;
46+
}
47+
48+
if (alias < 1) {
49+
// this interface has only one ipv4 adress
50+
// console.log(ifname, iface.address);
51+
ipAdresse = iface.address;
52+
} else {
53+
// console.log(ifname + ':' + alias, iface.address);
54+
// this single interface has multiple ipv4 addresses
55+
}
56+
++alias;
57+
});
58+
});
59+
return ipAdresse;
60+
}
61+
62+
askStructureId()
63+
{
64+
if (!this.__conf.structure_id)
65+
dialog.showMessageBox(this.window, {
66+
type: 'info',
67+
title: 'Set structure id',
68+
message: `Please set the app's structure id in ${this.getAppDataDir() + this.MODULE_NAME + '.json'}`,
69+
buttons: ['Ok']
70+
})
71+
}
4372
}
4473

4574
module.exports = LocalKeysCheck;

extensions/keys-checker/preload.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
const { contextBridge, ipcRenderer } = require('electron');
22
const ipcChannel = require('../../lib/icpChannel.js');
3+
const BasePreload = require('../../lib/BasePreload.js');
34

4-
class TouchUtils_preload extends require('../../lib/BasePreload.js')
5+
class TouchUtils_preload extends BasePreload
56
{
67
MODULE_NAME = "keys-checker";
8+
79
contextbridge_expose = {
810
'electronAPI': {
9-
getLocalKey: () => ipcRenderer.invoke('get-key')
11+
getExtraInfo: () => ipcRenderer.invoke('get-info')
1012
}
1113
};
1214

13-
getKeyPlease()
14-
{
15-
ipcChannel.sendSignalToMain('get-key').then(keys => {return keys.machine_id});
16-
}
17-
1815
setup() {}
1916
}
2017

extensions/loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Loader2
2121
// 'data' shoud be app.data
2222
static load(data) {
2323
this.mainWindow = TabsManager.mainWindow;
24-
this.mainTab = TabsManager.activeTab.tab;
24+
this.mainTab = TabsManager.getActiveTab();
2525
this.data = data;
2626

2727
// load modules -> no setup
@@ -80,6 +80,7 @@ class Loader2
8080
{
8181
try
8282
{
83+
if (!ext || !modules[ext]) return console.log(kleur.red("Error:"), ext, "is not a module!!");
8384
const ModuleClass = require(modules[ext]);
8485
if (typeof(ModuleClass) !== typeof(function () {}) || Object.getPrototypeOf(ModuleClass) !== BaseModule) { console.log(kleur.grey("Not loading " + ext + ": not a module")); return } ;
8586
const t = new ModuleClass()

extensions/splashscreen/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class Splashscreen extends require('../../lib/BaseModule')
4444
// setTimeout(TabsManager.setTab, 5000, mainTab);
4545
}
4646

47-
onNewTabCreated()
47+
onNewTabCreated(newTab)
4848
{
49-
this.tab.webContents.on('input-event', (e, input) => {
49+
newTab.webContents.on('input-event', (e, input) => {
5050
this.inputed = true;
5151
});
5252
this.log('listener set');

extensions/tab_browser/new_page.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

extensions/tab_browser/main.js renamed to extensions/toolbar/main.js

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ const fs = require('fs');
66
const icpChannel = require('../../lib/icpChannel');
77
const Env = require('../../env');
88
const { getPageTitle } = require('../../lib/utils');
9+
const BaseModule = require('../../lib/BaseModule');
10+
const kleur = require('kleur');
11+
const ipcChannel = require('../../lib/icpChannel');
912

1013
// Sample Module. Plase copy-paste this file into new module's main folder
11-
class Toolbar extends require('../../lib/BaseModule')
14+
class Toolbar extends BaseModule
1215
{
1316
MODULE_NAME = "toolbar"; // MUST be the same as the 'extension' field in config.json
1417
static toolbar_tab;
1518
tabs_count = 0;
1619
track_active_tab = false;
1720
first_avoided = false;
1821

19-
// required_modules = ['window-events'];
20-
2122
onNewTabCreated(new_tab, old_tab)
2223
{
2324
new_tab.webContents.setWindowOpenHandler((details) => {
@@ -33,48 +34,62 @@ class Toolbar extends require('../../lib/BaseModule')
3334
{
3435
if (this.__conf.hidden != true)
3536
{
36-
Toolbar.toolbar_tab = new WebContentsView({
37+
this.tab = new WebContentsView({
3738
webPreferences: {
3839
preload: path.join(__dirname, '../single_preload.js'),
3940
additionalArguments: ['--load-only=' + path.join(__dirname, 'toolbar_preload.js')],
4041
...Env.WEBVIEW_DEFAULT_PREFERENCES
4142
}});
43+
Toolbar.toolbar_tab = this.tab;
44+
this.tab.tab_id = 'toolbar';
4245

43-
this.tab = Toolbar.toolbar_tab;
44-
45-
Toolbar.toolbar_tab.webContents.loadURL(url.format({
46+
this.tab.webContents.loadURL(url.format({
4647
pathname: path.join(__dirname, this.__conf.toolbar_html),
4748
protocol: 'file'
4849
}));
4950

5051
this.warn({height: this.__conf.toolbar_width});
5152
if (this.__conf.default_url.protocol == 'file') this.__conf.default_url.pathname = path.join(__dirname, this.__conf.default_url.pathname);
52-
TabsManager.newSideTab(Toolbar.toolbar_tab, 'toolbar', {height: this.__conf.toolbar_width});
53+
TabsManager.newSideTab(this.tab, 'toolbar', {height: this.__conf.toolbar_width});
5354
TabsManager.newDefaultBounds({y: this.__conf.toolbar_width});
5455

55-
56-
this.newCtrlShortcut('r', () => { Toolbar.toolbar_tab.webContents.reload(); });
56+
this.newCtrlShortcut('r', () => { this.tab.webContents.reload(); });
5757

58-
fs.watch(__dirname, (event) => {if (event == "change") {Toolbar.toolbar_tab.webContents.reload(); this.log(this.__conf.toolbar_html, "has been modified! Reloading toolbar.")}});
58+
fs.watch(__dirname, (event) => {if (event == "change") {this.tab.webContents.reload(); this.log(this.__conf.toolbar_html, "has been modified! Reloading toolbar.")}});
5959

6060
icpChannel.newMainHandler('created-tab', (_, tab_url) => this.createNewTab(url.format(this.__conf.default_url)));
6161
icpChannel.newMainHandler('switch-tab', (_, index) => this.setActiveTab(index));
62-
icpChannel.newMainHandler('close-tab', (_, index) => this.closeTab(index));
62+
icpChannel.newMainHandler('closed-tab', (_, index) => this.closeTab(TabsManager.idToName(index)));
6363

64-
Toolbar.toolbar_tab.webContents.openDevTools({mode: 'detach'});
64+
this.tab.webContents.openDevTools({mode: 'detach'});
6565
}
6666
}
67-
67+
6868
late_setup()
6969
{
70-
if (this.__conf.create_on_open == true)
70+
new (require('../window-events/main'))().onNewTabCreated(this.tab);
71+
72+
if (this.__conf.create_on_open == true || Object.keys(TabsManager.tabs).length == 0)
7173
this.requestNewTab();
7274
}
7375

7476
// this method can be called from ANYWHERE (after initialization), thanks to the singleton behaviour of the modules.
7577
async requestNewTab(req_url = this.__conf.default_url)
7678
{
77-
icpChannel.sendSignalToRender('create-tab', Toolbar.toolbar_tab, await this.createNewTab(typeof(req_url) == 'string' ? req_url : url.format(req_url), true));
79+
icpChannel.sendSignalToRender('create-tab', this.tab, await this.createNewTab(typeof(req_url) == 'string' ? req_url : url.format(req_url), true));
80+
}
81+
82+
static requestCloseTabId(tab_id)
83+
{
84+
Toolbar.requestCloseTab(TabsManager.getNameTab(tab_id));
85+
}
86+
87+
static requestCloseTab(tab)
88+
{
89+
if (!tab || !tab.tab_id) return console.log('[', kleur.green("toolbar") , '] cannot close', tab && tab.tab_id);
90+
console.log('[', kleur.green("toolbar") , '] closing', tab.tab_id);
91+
icpChannel.sendSignalToRender('close-tab', Toolbar.toolbar_tab, tab.tab_id.substring(4));
92+
TabsManager.closeTab(tab);
7893
}
7994

8095
// force_url can be set to true ONLY from this extension's context, NOT from the browser's new tab request
@@ -85,22 +100,32 @@ class Toolbar extends require('../../lib/BaseModule')
85100
preload: path.join(__dirname, '../preload.js'), // Secure bridge
86101
...Env.WEBVIEW_DEFAULT_PREFERENCES
87102
}});
88-
TabsManager.setNewTab(newTab, "tab_" + this.tabs_count++);
89103
const tab_url = force_url ? requested_url : url.format(this.__conf.default_url);
90104
newTab.webContents.loadURL(tab_url);
91105
this.log("Created new tab at url:", tab_url);
92-
return getPageTitle(newTab.webContents);
106+
this.setTitleTracker(newTab);
107+
return {success: await TabsManager.setNewTab(newTab, "tab_" + this.tabs_count++), title: await getPageTitle(newTab.webContents), id: newTab.tab_id};
93108
}
94109

95-
setActiveTab(index) {
110+
async setActiveTab(index) {
96111
if (index < 0 || index >= this.tabs_count) return;
97112
TabsManager.setTab(/*index == 0 ? 'main' : */'tab_' + index);
98113
// mainWindow.webContents.send("tab-switched", { index });
99114
}
100115

101-
closeTab(tabId)
116+
setTitleTracker(tab)
117+
{
118+
tab.webContents.on('page-title-updated', (e, new_title) => {
119+
if (tab == TabsManager.getActiveTab())
120+
this.window.setTitle(new_title);
121+
icpChannel.sendSignalToRender('rename-tab', this.tab, {id: tab.tab_id, new_title: new_title});
122+
});
123+
}
124+
125+
closeTab(tab)
102126
{
103-
TabsManager.closeTab(tabId);
127+
this.log('renderer requested tab close')
128+
TabsManager.closeTabName(tab);
104129
}
105130
}
106131

0 commit comments

Comments
 (0)