Skip to content

Commit

Permalink
v 2.2.0 Beta
Browse files Browse the repository at this point in the history
New development window (DarkDev)
- Custom load, modifies the requests and allows modifying them
- Resource Download, utility to download darkorbit resources

DarkDev is in beta, it may have bugs
  • Loading branch information
kaiserdj committed Mar 10, 2021
1 parent 200b640 commit b955b94
Show file tree
Hide file tree
Showing 12 changed files with 1,180 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ Thanks go to these wonderful people ([emoji key](https://allcontributors.org/doc

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Story

My initial intention with this project was to create a client for darkorbit that could be used by any user with any operating system (Windows, mac or linux), and had better performance.

When I already had a stable version, I tried to contact darkorbit to give them the client and if they wanted, implement it, modify it, or whatever they wanted ..... but after many attempts:
- Twitter: I never received a reply
- Official darkorbit forum: They delete my posts, saying that I can't publish external links. After talking on discord with an admin, he told me the steps I should follow to publish a post correctly, without a link, as a suggestion, etc.
- Discord: They treated me as if I was trying to steal data or as if I was a hack
- etc...

I abandon the idea of ​​contacting Darkorbit.

From now on I will continue to develop utilities for the client, not only as a client to play, but also to develop. With the intention of learning more about electron, js and in general to practice programming, while having fun with it.

## Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Bigpoint or any of its subsidiaries or its affiliates. The official Bigpoint website can be found at https://www.bigpoint.net. "Bigpoint" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
125 changes: 123 additions & 2 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const { BrowserWindow } = require('electron');
const settings = require("electron-settings");
const fs = require("fs");
const path = require("path");
const axios = require("axios");

const tools = require("./tools");
const update = require("./update");
const useragent = require("./useragent");
const Credentials = require("./credentials/credentials");
const DarkDev = require("./darkDev/darkDev");
const defaultSettings = require("./defaultSettings.json");

class Client {
Expand All @@ -28,6 +32,7 @@ class Client {
this.menuTray;
this.tray = tools.tray(this);
this.credentials = new Credentials(this);
this.darkDev = new DarkDev(this);

await update();

Expand All @@ -47,6 +52,10 @@ class Client {
this.credentials.mb.showWindow();
}

this.core.app.on("browser-window-created", () => {
this.setCustomLoad();
})

return this;
})()
}
Expand Down Expand Up @@ -76,6 +85,8 @@ class Client {
window.webContents.openDevTools();
}

this.setCustomLoad();

if (this.arg.login) {
if (this.arg.login.length === 2) {
window.webContents.on('did-finish-load', () => {
Expand Down Expand Up @@ -135,8 +146,24 @@ class Client {
})

window.on("close", () => {
if (settings.getSync().autoClose && BrowserWindow.getAllWindows().length <= 2) {
global.app.quit();
if (this.arg.dev) {
let winFocused = BrowserWindow.getFocusedWindow();
winFocused.webContents.debugger.detach();
}

if (settings.getSync().autoClose) {
if (BrowserWindow.getAllWindows().length <= 3 && this.arg.dev === true) {
BrowserWindow.getAllWindows().forEach((win) => {
win.destroy();
})
this.core.app.quit();
}
if (BrowserWindow.getAllWindows().length <= 2 && this.arg.dev === false) {
BrowserWindow.getAllWindows().forEach((win) => {
win.destroy();
})
this.core.app.quit();
}
}
})

Expand Down Expand Up @@ -171,6 +198,100 @@ class Client {

return window;
}

setCustomLoad() {
if (!this.arg.dev) {
return;
}

let backup = settings.getSync();
let customLoad = backup.DarkDev.CustomLoad;

let windows = BrowserWindow.getAllWindows();

for (let win of windows) {
if (win.webContents.getURL().split(":")[0] === "file") {
return;
}

let statusDevTools = win.webContents.isDevToolsOpened();
if (!statusDevTools) {
win.webContents.openDevTools()
}

if (!win.webContents.debugger.isAttached()) {
win.webContents.debugger.attach("1.1");
}

if (!customLoad.enable) {
win.webContents.debugger.sendCommand("Fetch.enable", { patterns: [] });
win.webContents.debugger.removeAllListeners("message");
if (!statusDevTools) {
win.webContents.closeDevTools()
}
return;
}

let patterns = [];

for (let id in customLoad.list) {
if (customLoad.list[id].enable) {
patterns.push({ urlPattern: customLoad.list[id].match });
}
}

win.webContents.debugger.sendCommand("Fetch.enable", { patterns });

win.webContents.debugger.removeAllListeners("message");

win.webContents.debugger.on("message", async (event, method, params) => {
if (method !== "Fetch.requestPaused") {
return;
}

for (let id in customLoad.list) {
if (!customLoad.list[id].enable) {
continue;
}

let pattern = customLoad.list[id].match.replaceAll("/", "\\/");
pattern = pattern.replaceAll(".", "\\.");
pattern = pattern.replaceAll("*", ".*");
pattern = pattern.replace(/[+?^${}()|]/g, '\\$&');

let check = new RegExp(pattern).test(params.request.url);
if (check) {
let body;

if (customLoad.list[id].LocalFileEnable) {
body = fs.readFileSync(path.normalize(customLoad.list[id].LocalFile), { encoding: "base64" });
} else {
body = await this.get(customLoad.list[id].actionUrl);
}

win.webContents.debugger.sendCommand("Fetch.fulfillRequest", {
responseCode: 200,
requestId: params.requestId,
body
});

return;
}
}

alert(`Error when injecting custom load in the url: ${params.request.url}`);
win.webContents.debugger.sendCommand("Fetch.continueRequest", { requestId: params.requestId });
})
}
}

async get(url) {
return new Promise((resolve, reject) => {
axios.get(url, { responseType: 'arraybuffer' })
.then(response => resolve(Buffer.from(response.data, 'binary').toString('base64')))
.catch(error => reject(error));
});
}
}

module.exports = Client;
68 changes: 68 additions & 0 deletions darkDev/darkDev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { BrowserWindow, MenuItem, ipcMain } = require('electron');
const settings = require("electron-settings");

const CustomLoad = require("./tools/CustomLoad");
const ResourceDownload = require("./tools/ResourceDownload");

class DarkDev {
constructor(client) {
this.client = client;
this.customLoad;
this.window;

if (!this.client.arg.dev) {
return;
}

let options = {
'show': false,
'webPreferences': {
'preload': `${__dirname}/master.js`,
'contextIsolation': true,
'nodeIntegration': true,
'nodeIntegrationInWorker': true,
'enableRemoteModule': true,
'webSecurity': false,
'plugins': true,
'devTools': this.client.arg.dev
}
};

this.window = new BrowserWindow(options);

this.window.setMenuBarVisibility(false);

this.window.loadFile("./darkDev/index.html");

this.client.menuTray.insert(0, new MenuItem({
label: "DarkDev",
type: "normal",
click: () => this.window.show()
}));

this.client.menuTray.insert(1, new MenuItem({
type: "separator"
}));

this.window.on('close', (event) => {
event.preventDefault();
this.window.hide();
})

this.customLoad = new CustomLoad(this.client, this.window);

ipcMain.on("LoadConfigDarkDev", () => {
this.window.webContents.send("SendLoadConfigDarkDev", settings.getSync().DarkDev)
})

ipcMain.on('ResourceDownload', (event, opt) => {
this.resourceDownload(opt);
});
}

async resourceDownload(opt) {
await new ResourceDownload(this.window, opt);
}
}

module.exports = DarkDev;
Loading

0 comments on commit b955b94

Please sign in to comment.