Skip to content

Commit 36a4437

Browse files
committed
Semi stable version
1 parent 11ac93d commit 36a4437

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
1+
# Simple Webpage Accessor with Some Optional Features (SWASOF)
2+
3+
A brief explaination of each file's usage/effect
4+
5+
## extensions_conf (link)
6+
Is a link to the location of extensions_conf app's private AppData subdirectory. Contains every extension's configuration file (eg. electronAPI.json). Contains also data.json
7+
8+
## extensions_data
9+
Is a folder containing useful data for any extension. Not editable at runtime
10+
11+
## extensions_main
12+
13+
## extensions_preload
14+
15+
## lib
16+
17+
---------------
18+
19+
A brief explaination of each file's usage/effect
20+
121
## config.json
2-
when a script is mentioned in this file all the content of the parent context is passed as env to the script creator
22+
23+
## env.js
24+
25+
## forge.config.json
26+
Don't worry about this one
27+
28+
## index.html
29+
Test page
30+
31+
## main.js
32+
33+
## package.json
34+
35+
## PackageCreator.js
36+
37+
## preload.js
38+

extensions_main/autostart.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ class Autostarter extends require('../lib/BaseModule')
1010
{
1111
MODULE_NAME = "autostart";
1212

13-
setup()
13+
setup_linux()
1414
{
15-
// LINUX SETUP]
1615
this.log("setting autostart to", this.getAppData().autostart);
1716
if (this.getAppData().autostart == true)
1817
{
@@ -28,6 +27,14 @@ Exec=` + this.getAppConfig().app_info.app_executable;
2827
this.log("desktop file created");
2928
}
3029
}
30+
31+
setup_windows()
32+
{
33+
if (this.getAppData().autostart == true)
34+
app.setLoginItemSettings({
35+
openAtLogin: true
36+
})
37+
}
3138
}
3239

3340
module.exports = Autostarter;

lib/BaseModule.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('./path2')
33
const kleur = require('kleur');
44
const Env = require('../env');
5-
const { OPERATIVE_SYSTEM } = require('./Constants');
5+
const { OPERATING_SYSTEM } = require('./Constants');
66
const { app } = require('electron');
77

88
class BaseModule
@@ -39,16 +39,19 @@ class BaseModule
3939
// this.log('Setting up', this.module_name, 'config:', this.__conf, '...');
4040

4141
if (this.setup) this.setup();
42-
switch(OPERATIVE_SYSTEM)
42+
switch(OPERATING_SYSTEM)
4343
{
44-
case "linux": if (this.setup_linux) this.setup_linux();
44+
case 'linux': if (this.setup_linux) this.setup_linux();
45+
break ;
46+
case 'windows': if (this.setup_windows) this.setup_windows()
47+
break ;
4548
}
46-
// THIS SHOULD BE AFTER EVERY EXTENSSION IS INIT
47-
// if (this.late_setup) this.late_setup();
4849
this.is_active = true;
4950
this.log('... done');
5051
}
5152

53+
__late_start() { if (this.late_setup) this.late_setup(); }
54+
5255
// Colored logging! Use this instead of console.log()
5356
log(...message)
5457
{
@@ -70,7 +73,7 @@ class BaseModule
7073
isActive() {return this.is_active;}
7174

7275
// returns module's private folder
73-
appData()
76+
getAppDataDir()
7477
{
7578
return path.joinAppData(this.module_name);
7679
}

lib/Constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ module.exports =
1111
APPDATA_DIRNAME: 'webpage-accessor',
1212
DATA_CONF_PATH: 'extensions_conf/data.json',
1313
LINUX_AUTOSTART_DIR: path.join(app.getPath('home'), '.config', 'autostart'),
14-
OPERATIVE_SYSTEM: os.platform()
14+
OPERATING_SYSTEM: os.platform()
1515
};

lib/SAMPLE_MODULE.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('./path2')
33
// Sample Module. Plase copy-paste this file into new module's main folder
44
class SAMPLEMODULE extends require('./BaseModule')
55
{
6-
MODULE_NAME = "SAMPLEMODULE"; // Does not have to be the same as parent folder
6+
MODULE_NAME = "SAMPLEMODULE"; // MUST be the same as the 'extension' field in config.json
77

88
//// Constructor trace, please leave commented, unless necessary.
99
// constructor(window, tab) { super(window, tab); }
@@ -14,7 +14,7 @@ class SAMPLEMODULE extends require('./BaseModule')
1414
// linux specific setup section. Called after setup()
1515
setup_linux() {}
1616

17-
// Extra setup code here. Call
17+
// Extra setup code here. Called after every other service has already been setup
1818
late_setup() {}
1919
}
2020

main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const pc = require('./PackageCreator');
88
const kleur = require('kleur');
99
const { DATA_CONF_PATH } = require('./lib/Constants');
1010
const os = require('os');
11+
const BaseModule = require('./lib/BaseModule');
1112

1213
const DATA_FILE_PATH = path.joinAppData(DATA_CONF_PATH);
1314
const LOAD_DIR = path.join(__dirname, 'extensions_main');
@@ -82,7 +83,7 @@ async function createMainWindow()
8283
try
8384
{
8485
const ModuleClass = require(fullpath);
85-
if (typeof(ModuleClass) !== typeof(function () {})) { console.log(kleur.grey("Not loading " + ext + ": not a module")); return } ;
86+
if (typeof(ModuleClass) !== typeof(function () {}) || Object.getPrototypeOf(ModuleClass) !== BaseModule) { console.log(kleur.grey("Not loading " + ext + ": not a module")); return } ;
8687
const t = new ModuleClass()
8788
enabled_modules.push(t);
8889
t.__start(mainWindow, mainTab);
@@ -92,6 +93,9 @@ async function createMainWindow()
9293
console.log("Module not loaded:", e);
9394
}
9495
});
96+
enabled_modules.forEach(function (module) {
97+
if (module.isActive()) module.__late_start();
98+
});
9599

96100

97101
mainTab.webContents.toggleDevTools();

0 commit comments

Comments
 (0)