Skip to content

Commit

Permalink
Merge pull request #180 from JsSucks/configs
Browse files Browse the repository at this point in the history
Configs
  • Loading branch information
Jiiks authored Mar 19, 2018
2 parents e1456f5 + a150c3c commit 122036f
Show file tree
Hide file tree
Showing 30 changed files with 770 additions and 59 deletions.
2 changes: 1 addition & 1 deletion client/src/modules/contentmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class {
* returns {String}
*/
static get contentPath() {
return this._contentPath ? this._contentPath : (this._contentPath = Globals.getObject('paths').find(path => path.id === this.pathId).path);
return Globals.getPath(this.pathId);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions client/src/modules/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ export default new class extends Module {
return this.state[name];
}

getPath(id) {
return this.state.paths.find(path => path.id === id).path;
}

static get paths() {
return this.state.paths;
}

static get version() {
return this.state.version;
}

}
2 changes: 1 addition & 1 deletion client/src/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ export default new class Settings {
}

get dataPath() {
return this._dataPath ? this._dataPath : (this._dataPath = Globals.getObject('paths').find(p => p.id === 'data').path);
return Globals.getPath('data');
}
}
4 changes: 2 additions & 2 deletions client/src/modules/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export default class {
try {
Events.emit('update-check-end');
Logger.info('Updater',
`Latest Version: ${e.version} - Current Version: ${Globals.getObject('version')}`);
if (e.version !== Globals.getObject('version')) {
`Latest Version: ${e.version} - Current Version: ${Globals.version}`);
if (e.version !== Globals.version) {
this.updatesAvailable = true;
Events.emit('updates-available');
}
Expand Down
92 changes: 37 additions & 55 deletions core/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,41 @@
const path = require('path');
const sass = require('node-sass');

/**
* DEVELOPMENT VARIABLES
*/
const clientScriptPath = path.resolve(__dirname, '..', '..', 'client', 'dist').replace(/\\/g, '/');

const __DEV = {
TESTING: false,
clientScriptPath: `${clientScriptPath}/betterdiscord.client.js`
}

const __dataPath = path.resolve(__dirname, '..', '..', 'tests', 'data');
const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins');
const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes');
const __modulePath = path.resolve(__dirname, '..', '..', 'tests', 'modules');

const { Utils, FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Database } = require('./modules');
const { FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Database } = require('./modules');
const { BrowserWindow, dialog } = require('electron');

const Common = {};
const tests = true;
const _clientScript = tests
? path.resolve(__dirname, '..', '..', 'client', 'dist', 'betterdiscord.client.js')
: path.resolve(__dirname, 'betterdiscord.client.js');
const _dataPath = tests
? path.resolve(__dirname, '..', '..', 'tests', 'data')
: path.resolve(__dirname, 'data');
const _extPath = tests
? path.resolve(__dirname, '..', '..', 'tests', 'ext')
: path.resolve(__dirname, 'ext');
const _pluginPath = path.resolve(_extPath, 'plugins');
const _themePath = path.resolve(_extPath, 'themes');
const _modulePath = path.resolve(_extPath, 'modules');

const paths = [
{ id: 'cs', path: _clientScript.replace(/\\/g, '/') },
{ id: 'data', path: _dataPath.replace(/\\/g, '/') },
{ id: 'ext', path: _extPath.replace(/\\/g, '/') },
{ id: 'plugins', path: _pluginPath.replace(/\\/g, '/') },
{ id: 'themes', path: _themePath.replace(/\\/g, '/') },
{ id: 'modules', path: _modulePath.replace(/\\/g, '/') }
];

const sparkplug = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');

const dummyArgs = {
'version': '2.0.0a',
'paths': [
{ 'id': 'base', 'path': 'basePath' },
{ 'id': 'data', 'path': __dataPath },
{ 'id': 'plugins', 'path': __pluginPath },
{ 'id': 'themes', 'path': __themePath },
{ 'id': 'modules', 'path': __modulePath }
]
};
const dbInstance = new Database(dummyArgs.paths.find(path => path.id === 'data').path);
console.log(dummyArgs);
const Common = {};
const globals = {
version: '2.0.0a',
paths
}

const dbInstance = new Database(paths.find(path => path.id === 'data').path);

class Comms {

Expand Down Expand Up @@ -120,15 +122,14 @@ class BetterDiscord {

constructor(args) {
if (BetterDiscord.loaded) {
// Creating two BetterDiscord objects???
console.log('Creating two BetterDiscord objects???');
return null;
}
BetterDiscord.loaded = true;

this.injectScripts = this.injectScripts.bind(this);
this.ignite = this.ignite.bind(this);
Common.Config = new Config(args || dummyArgs);
Common.Config = new Config(globals);
this.comms = new Comms(this);
this.init();
}
Expand All @@ -139,16 +140,6 @@ class BetterDiscord {

this.csseditor = new CSSEditor(this);

//Log some events for now
//this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`));
//this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`));
//this.windowUtils.webContents.on('did-get-response-details', e => this.ignite(this.windowUtils.window));
//this.windowUtils.webContents.on('page-favicon-updated', e => this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`));
//this.windowUtils.webContents.on('will-navigate', e => this.windowUtils.executeJavascript(`console.info('will-navigate');`));
//this.windowUtils.webContents.on('did-navigate', e => this.windowUtils.executeJavascript(`console.info('did-navigate');`));
//this.windowUtils.webContents.on('did-navigate-in-page', e => this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`));
//this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true));

this.windowUtils.events('did-get-response-details', () => this.ignite(this.windowUtils.window));
this.windowUtils.events('did-finish-load', e => this.injectScripts(true));

Expand All @@ -157,13 +148,13 @@ class BetterDiscord {
});

setTimeout(() => {
if (__DEV) { this.injectScripts(); }
this.injectScripts();
}, 500);
}

async waitForWindow() {
const self = this;
return new Promise((resolve, reject) => {
return new Promise(resolve => {
const defer = setInterval(() => {
const windows = BrowserWindow.getAllWindows();

Expand All @@ -173,13 +164,7 @@ class BetterDiscord {
});
}

if (__DEV && __DEV.TESTING && windows.length > 0) {
resolve(windows[0]);
clearInterval(defer);
return;
}

if (windows.length === 1 && windows[0].webContents.getURL().includes("discordapp.com")) {
if (windows.length === 1 && windows[0].webContents.getURL().includes('discordapp.com')) {
resolve(windows[0]);
clearInterval(defer);
}
Expand All @@ -189,15 +174,12 @@ class BetterDiscord {

ignite(window) {
//Hook things that Discord removes from global. These will be removed again in the client script
const sp = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
window.webContents.executeJavaScript(`require("${sp}");`);
window.webContents.executeJavaScript(`require("${sparkplug}");`);
}

injectScripts(reload = false) {
console.log(`RELOAD? ${reload}`);
if (__DEV) {
this.windowUtils.injectScript(__DEV.clientScriptPath);
}
this.windowUtils.injectScript(paths.find(path => path.id === 'cs').path);
}

get fileUtils() { return FileUtils; }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added tests/ext/themes/SimplerFlat/.DS_Store
Binary file not shown.
198 changes: 198 additions & 0 deletions tests/ext/themes/SimplerFlat/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{
"info": {
"name": "SimplerFlat",
"authors": [ "Qwerasd" ],
"version": 1.02,
"description": "SimplerFlat is a solid colored dark flat theme with customizable colors.",
"type": "sass"
},
"main": "index.scss",
"defaultConfig": [
{
"category": "not default",
"category_name": "not default",
"type": "drawer",
"settings": [
{
"id": "color-light",
"type": "color",
"value": "#3E3E3E",
"text": "Light Color",
"hint": "The color of things that are lighter than the chat panel."
},
{
"id": "color-medium",
"type": "color",
"value": "#2E2E2E",
"text": "Medium Color",
"hint": "The color of the chat panel."
},
{
"id": "color-dark",
"type": "color",
"value": "#1E1E1E",
"text": "Dark Color",
"hint": "The color of the channels, and members panels."
},
{
"id": "color-very-dark",
"type": "color",
"value": "#0E0E0E",
"text": "Very Dark Color",
"hint": "The color of the guilds sidebar."
},
{
"id": "main-color",
"type": "color",
"value": "#00FAFA",
"text": "Accent Color",
"hint": "For when a little bit of sophistication is required."
},
{
"id": "main-text-color",
"type": "color",
"value": "#FAFAFA",
"text": "Text Color",
"hint": "Most text will be this color."
},
{
"id": "chat-text-color",
"type": "color",
"value": "#FFFFFF",
"text": "Chat Color",
"hint": "Text in the chat pane will be this color."
},
{
"id": "code-text-color",
"type": "color",
"value": "#CCCCCC",
"text": "Code Color",
"hint": "Non syntax-highlighted code in codeblocks will be this color."
},
{
"id": "tint-color",
"type": "color",
"value": "#00FAFA",
"text": "Tint Color",
"hint": "Tint all of the background colors using this color."
},
{
"id": "tint-strength",
"type": "slider",
"value": 0,
"min": 0,
"max": 100,
"step": 0.5,
"unit": "%",
"multi": "0.5",
"text": "Tint Strength",
"hint": "How strongly to tint the background colors."
},
{
"id": "collapsing-panels",
"type": "bool",
"value": false,
"text": "Collapsing Side Panels",
"hint": "Fancy channels and members panels that hide themselves when not needed."
},
{
"id": "compact-server-list",
"type": "bool",
"value": false,
"text": "Compact Server List",
"hint": "Squishes together your servers so that they take up less space."
}
]
}
],
"configSchemes": [
{
"id": "default",
"name": "Default Colors",
"hint": "The basic colors -- good for tinting.",
"settings": [
{
"category": "default",
"settings": [
{
"id": "color-light",
"value": "#3E3E3E"
},
{
"id": "color-medium",
"value": "#2E2E2E"
},
{
"id": "color-dark",
"value": "#1E1E1E"
},
{
"id": "color-very-dark",
"value": "#0E0E0E"
},
{
"id": "main-color",
"value": "#00FAFA"
},
{
"id": "main-text-color",
"value": "#FAFAFA"
},
{
"id": "chat-text-color",
"value": "#FFFFFF"
},
{
"id": "code-text-color",
"value": "#CCCCCC"
}
]
}
]
},
{
"id": "high-contrast",
"name": "High Contrast",
"hint": "Very high contrast scheme.",
"settings": [
{
"category": "default",
"settings": [
{
"id": "color-light",
"value": "#CCCCCC"
},
{
"id": "color-medium",
"value": "#000000"
},
{
"id": "color-dark",
"value": "#000000"
},
{
"id": "color-very-dark",
"value": "#000000"
},
{
"id": "main-color",
"value": "#FFFFFF"
},
{
"id": "main-text-color",
"value": "#FFFFFF"
},
{
"id": "chat-text-color",
"value": "#FFFFFF"
},
{
"id": "code-text-color",
"value": "#FFFFFF"
}
]
}
]
}
]
}
Loading

0 comments on commit 122036f

Please sign in to comment.