Skip to content

Commit 4d338d0

Browse files
committed
better workflow, better preload operations
1 parent 3801ba5 commit 4d338d0

File tree

11 files changed

+181
-79
lines changed

11 files changed

+181
-79
lines changed

.github/workflows/push.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
git config user.name "github-actions[bot]"
3434
git config user.email "github-actions[bot]@users.noreply.github.com"
3535
36+
# save artifact inside virutal machine
37+
cp -r dist ../$(basename $GITHUB_WORKSPACE)/dist/*
38+
39+
3640
# Create or switch to artifacts branch
3741
git fetch origin artifacts || true
3842
git checkout -B artifacts origin/artifacts || git checkout -b artifacts

config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{
4040
"enabled": true,
4141
"remap_to_pointeraction": true,
42-
"disable_physical_keyboard": true,
42+
"disable_physical_keyboard": false,
4343
"disable_virtual_keyboard": false,
4444
"one_button_at_a_time": true,
4545
"actions":
@@ -87,7 +87,7 @@
8787
},
8888
"autostart":
8989
{
90-
"desktop_filename": "webpage-accessor.desktop",
90+
"desktop_filename": "webpage_accessor.desktop",
9191
"extension": "autostart"
9292
},
9393
"splashscreen":

extensions/loader.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const EXT_LOAD_DIR = __dirname;
99

1010
class Loader2
1111
{
12-
static load(enabled_modules, mainWindow, mainTab) {
12+
// 'data' shoud be app.data
13+
static load(enabled_modules, mainWindow, mainTab, data) {
1314
fs.readdirSync(EXT_LOAD_DIR).forEach(function (ext)
1415
{
1516
const main = path.join(EXT_LOAD_DIR, ext, 'main.js');
@@ -25,7 +26,7 @@ class Loader2
2526
if (typeof(ModuleClass) !== typeof(function () {}) || Object.getPrototypeOf(ModuleClass) !== BaseModule) { console.log(kleur.grey("Not loading " + ext + ": not a module")); return } ;
2627
const t = new ModuleClass()
2728
enabled_modules.push(t);
28-
t.__start(mainWindow, mainTab);
29+
t.__start(mainWindow, mainTab, data);
2930
}
3031
catch (e)
3132
{

extensions/preload.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ const Env = require('../env');
55
const LOAD_DIR = __dirname;
66

77
// V2
8+
window.enabled_extensions = []
89
fs.readdirSync(LOAD_DIR).forEach(function (ext) {
910
const preload = path.join(LOAD_DIR, ext, 'preload.js');
1011
if (!fs.existsSync(preload)) return
1112
try
1213
{
13-
require(preload);
14-
if (Env.DEBUG_MODE)
15-
console.log(ext, "preloaded");
14+
console.log('preloadimg', preload);
15+
const PreloadClass = require(preload);
16+
console.log('preloadimg', preload);
17+
console.log(new PreloadClass());
18+
if (typeof(PreloadClass) !== typeof(function () {}) || Object.getPrototypeOf(PreloadClass) !== BasePreload) { console.log(kleur.grey("Not loading " + ext + ": not a module")); return } ;
19+
console.log('preloadimg', preload);
20+
// const t = new PreloadClass();
21+
// enabled_modules.push(t);
22+
// t.__start(mainWindow, mainTab, data);
1623
}
1724
catch (e)
1825
{
19-
console.log('Module', ext, 'not loaded:', e);
2026
if (Env.DEBUG_MODE)
2127
console.log(ext, "not preloaded");
2228
}

extensions/touch-utils/preload.js

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,78 @@
11
const { contextBridge, ipcRenderer } = require('electron');
22
const { createMouseEvent, sendMouseEvent } = require('../../lib/utils.js')
3+
const fs = require('fs');
4+
const path = require('path')
35

4-
const LONG_PRESS_DELAY = 500; // longpress duration in ms
5-
var longPressTimer = null;
6+
class TouchUtils_preload extends require('../../lib/BasePreload.js')
7+
{
8+
LONG_PRESS_DELAY = 500; // longpress duration in ms
9+
longPressTimer = null;
610

7-
var lastTouchedObject = null; // necessary for doubletap
8-
var touchTime = 0;
11+
lastTouchedObject = null; // necessary for doubletap
12+
touchTime = 0;
913

10-
const fs = require('fs');
11-
const path = require('path')
12-
const bubbleStyle = fs.readFileSync(path.join(__dirname, './bubble.html'));
13-
console.log("Bubble style:", bubbleStyle);
14+
start()
15+
{
16+
bubbleStyle = fs.readFileSync(path.join(__dirname, './bubble.html'));
17+
console.log("Bubble style:", bubbleStyle);
1418

15-
// detect long press (trigger left-click + contextmenu) and
16-
// detect touched item for events sent from main
17-
window.addEventListener('pointerdown', (e, input) => {
18-
// Start timer on mouse down
19-
if (!longPressTimer)
20-
longPressTimer = setTimeout(() => {
21-
// Trigger long press event after delay
22-
console.log("long pressss!!!");
23-
sendMouseEvent('contextmenu', e);
24-
sendMouseEvent('pointerdown', e);
25-
}, LONG_PRESS_DELAY);
19+
// detect long press (trigger left-click + contextmenu) and
20+
// detect touched item for events sent from main
21+
window.addEventListener('pointerdown', (e, input) => {
22+
// Start timer on mouse down
23+
if (!longPressTimer)
24+
longPressTimer = setTimeout(() => {
25+
// Trigger long press event after delay
26+
console.log("long pressss!!!");
27+
sendMouseEvent('contextmenu', e);
28+
sendMouseEvent('pointerdown', e);
29+
}, LONG_PRESS_DELAY);
2630

27-
lastTouchedObject = e.target;
28-
touchTime = Date.now();
29-
31+
lastTouchedObject = e.target;
32+
touchTime = Date.now();
33+
3034

31-
// Summon Bubble when screen is touched
32-
const bubble = document.createElement("span");
33-
bubble.classList.add("bubble");
34-
bubble.style.left = `${e.clientX - bubble.style.width}px`;
35-
bubble.style.top = `${e.clientY - bubble.style.height}px`;
35+
// Summon Bubble when screen is touched
36+
const bubble = document.createElement("span");
37+
bubble.classList.add("bubble");
38+
bubble.style.left = `${e.clientX - bubble.style.width}px`;
39+
bubble.style.top = `${e.clientY - bubble.style.height}px`;
3640

37-
const style = document.createElement("style");
38-
style.textContent = bubbleStyle;
39-
document.head.appendChild(style);
40-
document.body.appendChild(bubble);
41+
const style = document.createElement("style");
42+
style.textContent = bubbleStyle;
43+
document.head.appendChild(style);
44+
document.body.appendChild(bubble);
4145

42-
// remove after animation ends
43-
bubble.addEventListener("animationend", () => {
44-
bubble.remove();
45-
});
46-
});
46+
// remove after animation ends
47+
bubble.addEventListener("animationend", () => {
48+
bubble.remove();
49+
});
50+
});
4751

48-
// same
49-
window.addEventListener('pointerup', (event) => {
50-
// Cancel timer on mouseup
51-
if (longPressTimer) {
52-
clearTimeout(longPressTimer);
53-
longPressTimer = null;
52+
// same
53+
window.addEventListener('pointerup', (event) => {
54+
// Cancel timer on mouseup
55+
if (longPressTimer) {
56+
clearTimeout(longPressTimer);
57+
longPressTimer = null;
58+
}
59+
});
60+
61+
// radial double-click signal forward
62+
ipcRenderer.on('double-click2', function (e, pos)
63+
{
64+
var dbc_event = e;
65+
dbc_event.target = lastTouchedObject;
66+
dbc_event.clientX = pos.x;
67+
dbc_event.clientY = pos.x;
68+
const dblClickEvent = createMouseEvent('dblclick', dbc_event);
69+
// console.log("###lastItem:", lastTouchedObject);
70+
if (lastTouchedObject && Date.now() < touchTime + 1000)
71+
lastTouchedObject.dispatchEvent(dblClickEvent);
72+
else
73+
document.dispatchEvent(dblClickEvent);
74+
});
5475
}
55-
});
56-
57-
// radial double-click signal forward
58-
ipcRenderer.on('double-click2', function (e, pos)
59-
{
60-
var dbc_event = e;
61-
dbc_event.target = lastTouchedObject;
62-
dbc_event.clientX = pos.x;
63-
dbc_event.clientY = pos.x;
64-
const dblClickEvent = createMouseEvent('dblclick', dbc_event);
65-
// console.log("###lastItem:", lastTouchedObject);
66-
if (lastTouchedObject && Date.now() < touchTime + 1000)
67-
lastTouchedObject.dispatchEvent(dblClickEvent);
68-
else
69-
document.dispatchEvent(dblClickEvent);
70-
});
76+
}
77+
78+
module.exports = TouchUtils_preload
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[Desktop Entry]
2-
Name=webpage-accessor
2+
Name=webpage_accessor
33
Comment=webpage accessor autostart script
44
Type=Application
5-
Exec=webpage-accessor
5+
Exec=webpage_accessor

lib/BaseModule.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class BaseModule
99
{
1010
// extensions's configuration file content. Different from app.conf
1111
__conf = null;
12+
__data = null;
1213

1314
window = null;
1415
tab = null;
@@ -24,7 +25,7 @@ class BaseModule
2425
late_setup() {}
2526

2627
// extension's constructors are called after window creation and after app.ready().
27-
__start(window, tab)
28+
__start(window, tab, data)
2829
{
2930
this.window = window;
3031
this.tab = tab;
@@ -42,6 +43,7 @@ class BaseModule
4243
if (!this.__conf) this.warn('__conf not defined.');
4344
else if (this.__conf.enabled == false) return;
4445

46+
this.__data = data;
4547
// this.log('Setting up', this.module_name, 'config:', this.__conf, '...');
4648

4749
this.setup();

lib/BasePreload.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const fs = require('fs');
2+
const path = require('./path2')
3+
const kleur = require('kleur');
4+
const Env = require('../env');
5+
const { OPERATING_SYSTEM } = require('./Constants');
6+
const { app } = require('electron');
7+
8+
// like BaseModule but with less expensive features
9+
class BasePreload
10+
{
11+
// extensions's configuration file content. Different from app.conf
12+
__conf = null;
13+
__data = null;
14+
15+
window = null;
16+
tab = null;
17+
module_name = "";
18+
is_active = false;
19+
20+
constructor() {}
21+
22+
// available functions to be overloaded
23+
setup() {}
24+
25+
// extension's constructors are called after window creation and after app.ready().
26+
__start(window, tab)
27+
{
28+
29+
this.window = window;
30+
this.tab = tab;
31+
this.module_name = this.MODULE_NAME || 'BaseModule';
32+
33+
if (this.module_name == 'BaseModule')
34+
this.conf_file_path = path.joinConfigDir('data.json');
35+
else
36+
this.conf_file_path = path.joinConfigDir(this.module_name + '.json');
37+
38+
if (fs.existsSync(this.conf_file_path))
39+
try { this.__conf = JSON.parse(fs.readFileSync(this.conf_file_path, 'utf-8')); }
40+
catch (e) { this.warn('Could not load conf file for', this.module_name, ':', e, '.'); }
41+
42+
if (!this.__conf) this.warn('__conf not defined.');
43+
else if (this.__conf.enabled == false) return;
44+
45+
// this.log('Setting up', this.module_name, 'config:', this.__conf, '...');
46+
47+
this.setup();
48+
}
49+
50+
// Colored logging! Use this instead of console.log()
51+
log(...message)
52+
{
53+
if (Env.DEBUG_MODE) console.log('[', kleur.green(this.module_name), ']:', ...message);
54+
}
55+
warn(...message)
56+
{
57+
if (Env.DEBUG_MODE) console.log('[', kleur.yellow(this.module_name), ']:', ...message);
58+
}
59+
err(...message)
60+
{
61+
if (Env.DEBUG_MODE) console.log('[', kleur.red(this.module_name), ']:', ...message);
62+
}
63+
64+
// sets active status
65+
setActive(active = true) {this.is_active = active;}
66+
67+
// returns active status
68+
isActive() {return this.is_active;}
69+
70+
// setup Windows??
71+
}
72+
73+
module.exports = BasePreload;

lib/Constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports =
88
{
99
EXT_CONFIGS_DIR: 'extensions_conf',
1010
EXT_DATA_DIR: 'extensions_data',
11-
APPDATA_DIRNAME: 'webpage-accessor',
11+
APPDATA_DIRNAME: 'webpage_accessor',
1212
DATA_CONF_PATH: 'extensions_conf/data.json',
1313
LINUX_AUTOSTART_DIR: path.join(app.getPath('home'), '.config', 'autostart'),
1414
OPERATING_SYSTEM: os.platform()

lib/path2.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ class path2
2828
static already_required = false;
2929
}
3030

31-
// this section creates a link to extensions_conf inside appdata at the root of the app. Developer option
31+
// this section creates a link to extensions_conf inside appdata at the root of the app. Developer util
3232
if (!path2.already_required)
3333
{
3434
app.whenReady().then(function ()
3535
{
36-
console.log('creating dir',path2.config_location )
3736
if (!fs.existsSync(path2.config_location))
3837
try {fs.mkdirSync(path2.config_location, { recursive: true });}
3938
catch (e) {console.log("could not create path to", EXT_CONFIGS_DIR, "in", path2.appData, ".", )}
4039
if (findAppArg('create_config_link') && !fs.existsSync(path.join(__dirname, '..', EXT_CONFIGS_DIR)))
41-
fs.symlinkSync(path2.config_location, path.join(appData, '..', EXT_CONFIGS_DIR));
40+
{
41+
console.log('creating dir',path2.config_location )
42+
fs.symlinkSync(path2.config_location, path.join(__dirname, '..', EXT_CONFIGS_DIR));
43+
}
4244
});
4345
path2.already_required = true;
4446
}

0 commit comments

Comments
 (0)