Skip to content

Commit aae4aa5

Browse files
committed
restored extensions_main
1 parent 12dba0a commit aae4aa5

File tree

6 files changed

+188
-3
lines changed

6 files changed

+188
-3
lines changed

extensions_conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/leonardo/.config/Webpage_Accessor/extensions_conf

extensions_main/electronAPI.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { app, ipcMain } = require('electron');
2+
const fs = require('fs');
3+
4+
// Sample Module. Plase copy-paste this file into new module's main folder
5+
class ElectronAPI extends require('../lib/BaseModule')
6+
{
7+
MODULE_NAME = "electronAPI"; // MUST be the same as file name (required to access conf file)
8+
9+
//// Constructor trace, please leave commented, unless necessary.
10+
// constructor(window, tab) { super(window, tab); }
11+
12+
// 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());
18+
19+
app.commandLine.appendSwitch('touch-events', 'enabled');
20+
// app.commandLine.appendSwitch('enable-pointer-events');
21+
}
22+
23+
async readFile(path)
24+
{
25+
console.log("reading file");
26+
try {
27+
return fs.readFileSync(path, 'utf-8');
28+
} catch (err) {
29+
console.error(err);
30+
return null;
31+
}
32+
}
33+
34+
async getLocalKey()
35+
{
36+
try {
37+
return JSON.parse(fs.readFileSync(KEYS_PATH, 'utf-8'));
38+
} catch (err) {
39+
console.error(err);
40+
return null;
41+
}
42+
}
43+
}
44+
45+
module.exports = ElectronAPI;

extensions_main/keys-checker.js

Whitespace-only changes.

extensions_main/touch-utils.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const { app } = require("electron");
2+
3+
// radial double-click
4+
class DoubleClick extends require('../lib/BaseModule')
5+
{
6+
MODULE_NAME = "touch-utils"; // MUST be the same as file name (required to access conf file)
7+
8+
lstLeftPress = 0;
9+
lstLeftPos = {x: 0, y:0};
10+
lstRightPress = 0;
11+
lstRightPos = {x:0, y:0};
12+
13+
//// Constructor trace, please leave commented, unless necessary.
14+
// constructor(window, tab) { super(window, tab); }
15+
16+
17+
setup()
18+
{
19+
this.tab.webContents.on('input-event', (event, input) => {
20+
if (input.type != 'mouseMove')
21+
this.log("sending an", input.type);
22+
switch(input.type)
23+
{
24+
case 'mouseDown':
25+
switch(input.button)
26+
{
27+
case 'left':
28+
this.looseDoubleClickCheck(input, event);
29+
this.lstLeftPress = Date.now();
30+
this.lstLeftPos = {x: input.x, y: input.y};
31+
break ;
32+
case 'right':
33+
this.lstRightPress = Date.now();
34+
this.lstRightPos = {x: input.x, y: input.y};
35+
break ;
36+
}
37+
break ;
38+
case 'gestureTapDown' :
39+
this.looseDoubleClickCheck(input, event);
40+
break ;
41+
}
42+
});
43+
44+
if (this.__conf.remap_to_pointeraction == true)
45+
{
46+
this.warn("mapping touch inputs to mouse imputs");
47+
app.commandLine.appendSwitch("touch-events", "disabled");
48+
app.commandLine.appendSwitch("enable-pointer-events");
49+
}
50+
51+
if (this.__conf.disable_keyboard == true)
52+
{
53+
this.warn("disabling keyboard");
54+
this.tab.webContents.on("before-input-event", (event, input) => {
55+
if (input.type === 'keyDown' || input.type === 'keyUp')
56+
event.preventDefault();
57+
});
58+
}
59+
}
60+
61+
async looseDoubleClickCheck(input, event)
62+
{
63+
if (Date.now() > this.lstLeftPress + this.__conf.doubleclick_max_delay)
64+
return ;
65+
const dx = input.x - this.lstLeftPos.x;
66+
const dy = input.y - this.lstLeftPos.y;
67+
if ((dx != 0 || dy != 0) && dx * dx + dy * dy < this.__conf.doubleclick_sqr_radius)
68+
{
69+
this.tab.webContents.send('double-click2', { x: input.x, y: input.y });
70+
this.log("Firing!");
71+
}
72+
else
73+
this.log("radius exceeded or zero");
74+
this.lstLeftPress = 0;
75+
}
76+
}
77+
78+
module.exports = DoubleClick;

extensions_main/window-events.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { app, globalShortcut } = require('electron');
2+
const {checkActiveModules} = require('../main')
3+
4+
// Sample Module. Plase copy-paste this file into new module's main folder
5+
class WindowSetup extends require('../lib/BaseModule')
6+
{
7+
MODULE_NAME = "window-events"; // MUST be the same as file name (required to access conf file)
8+
9+
//// Constructor trace, please leave commented, unless necessary.
10+
// constructor(window, tab) { super(window, tab); }
11+
12+
// Setup code here. This function is called in BaseModule's constructor.
13+
setup()
14+
{
15+
this.requireDataConf();
16+
17+
this.window.on('resize', () => {
18+
if (this.window.isFullScreen()) return ;
19+
this.tab.setBounds({x: 0, y: 0 , height: this.window.getContentBounds().height, width: this.window.getContentBounds().width});
20+
this.logWindowDimensions('resize');
21+
});
22+
this.window.on('enter-full-screen', () => {
23+
this.tab.setBounds({x: 0, y: 0 , height: this.window.getContentBounds().height, width: this.window.getContentBounds().width});
24+
this.logWindowDimensions('enter fullscreen');
25+
});
26+
this.window.on('leave-full-screen', () => {
27+
this.tab.setBounds({x: 0, y: 0 , height: this.window.getContentBounds().height, width: this.window.getContentBounds().width});
28+
this.logWindowDimensions('leave fullscreen');
29+
});
30+
31+
globalShortcut.register('f', () => {
32+
this.window.setFullScreen(!this.window.isFullScreen());
33+
});
34+
globalShortcut.register('d', () => {
35+
this.tab.webContents.toggleDevTools();
36+
});
37+
globalShortcut.register('c', () => {
38+
checkActiveModules();
39+
});
40+
41+
if (this.__data.fullscreen == true) this.window.setFullScreen(true);
42+
}
43+
44+
logWindowDimensions(operation = '')
45+
{
46+
this.log(operation + ' Bounds:', this.window.getContentBounds());
47+
this.log(operation + ' Size:', this.window.getContentSize());
48+
}
49+
}
50+
51+
module.exports = WindowSetup;

lib/path2.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ class path2
1111
static joinAppData(...dir) {return path.join(path2.__dirname, ...dir);}
1212
static joinConfigDir(...dir) {return path.join(path2.__dirname, EXT_CONFIGS_DIR, ...dir);}
1313
static join(...dir) {return path.join(...dir);}
14+
15+
static already_required = false;
16+
}
17+
18+
if (!path2.already_required)
19+
{
20+
console.log('creating dir',path2.config_location )
21+
try {fs.mkdirSync(path2.config_location, { recursive: true });}
22+
catch (e) {console.log("could not create path to", EXT_CONFIGS_DIR, "in", path2.__dirname, ".", )}
23+
if (!fs.existsSync(path.join(__dirname, '..', EXT_CONFIGS_DIR)))
24+
fs.symlinkSync(path2.config_location, path.join(__dirname, '..', EXT_CONFIGS_DIR));
25+
26+
path2.already_required = true;
1427
}
1528

16-
try {fs.mkdirSync(path2.__dirname, { recursive: true });}
17-
catch (e) {console.log("could not create path to", EXT_CONFIGS_DIR, "in", path2.__dirname, ".", )}
18-
fs.symlinkSync(path2.config_location, path.join(__dirname, '..', EXT_CONFIGS_DIR));
1929

2030
module.exports = path2;

0 commit comments

Comments
 (0)