Permalink
Browse files

Checkpoint checkin, starting to work on main GUI.

  • Loading branch information...
roncli committed Apr 4, 2017
1 parent 553ea28 commit daf07904651b5d061a23490b55cdf1c582b9a232
@@ -41,3 +41,6 @@ jspm_packages

# Electron
dist

# Settings
settings.js
@@ -2,14 +2,14 @@ const {app, BrowserWindow} = require("electron");

var win,
createWindow = () => {
win = new BrowserWindow({show: false, width: 800, height: 600, minWidth: 800, minHeight: 600, icon: __dirname + "/../logo/logo.ico"}); // TODO: Get the right icon.
win.loadURL("file://" + __dirname + "/site/index.htm");
win = new BrowserWindow({show: false, width: 800, height: 600, minWidth: 800, minHeight: 600, icon: __dirname + "/../logo/logo.ico", title: "Hyperdrive Toolkit"}); // TODO: Get the right icon.
win.loadURL(`file://${__dirname}/site/index.htm`);
win.setMenu(null);
win.maximize();
win.toggleDevTools(); // TODO: Remove for release.

win.once("ready-to-show", () => {
win.show();
win.toggleDevTools(); // TODO: Remove for release.
});

win.on("closed", () => {
@@ -18,6 +18,9 @@
"url": "https://github.com/roncli/HyperdriveToolkit.git"
},
"dependencies": {
"bootstrap": "3.3.7",
"express": "4.15.2",
"jquery": "3.2.1",
"tmi.js": "1.1.2",
"twitch-api": "0.4.6"
},

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,27 @@
body {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
}

#menu {

}

#channels {

}

#display {
flex-grow: 1;
}

#input {

}

#inputbox {
width: 100%;
height: 1.2em;
}
@@ -1 +1,34 @@
TESTING!
<html>
<head>
<script src="js/index.js"></script>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script>$ = jQuery = require("jquery")</script>
<script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"></link>
<link href="../node_modules/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet"></link>
<link href="css/index.css" rel="stylesheet"></script>
</head>
<body>
<div id="menu">Menu</div>
<div id="channels">
<ul class="nav nav-tabs">
<li><a data-toggle="tab" href="#roncli">#roncli</a>
</ul>
</div>
<div id="display">
<!--
HTML for each channel:
<div id="channel">
<div id="chat">
<div id="topic"></div>
<div id="text"></div>
</div>
<div id="users"></div>
</div>
-->
</div>
<div id="input">
<input type="text" id="inputbox" />
</div>
</body>
</html>
@@ -0,0 +1,9 @@
var EventEmitter = require("events");

class Chat extends EventEmitter {
constructor() {
super();
}
}

module.exports = Chat;
@@ -0,0 +1,5 @@
class DataStore {
constructor() {}
}

module.exports = DataStore;
@@ -0,0 +1,5 @@
class Gui {
constructor() {}
}

module.exports = Gui;
@@ -0,0 +1,16 @@
var Twitch = require("./js/modules/chat/twitch"), // TODO: Load modules
settings = require("./js/settings"),
client = new Twitch(settings),
channels = [];

client.on("connected", (address, port) => {
document.getElementById("output").innerHTML += "Connected on address " + address + " port " + port + "<br />";
});

client.on("message", (channel, username, displayname, text) => {
document.getElementById("text").innerHTML += "<b>" + displayname + "</b>: " + text + "<br />";
});

client.authorize().then(() => {
client.connect();
});
@@ -0,0 +1,8 @@
<html>
<head>
<title>Hyperdrive Toolkit - Twitch OAuth Redirect</title>
</head>
<body>
Hyperdrive Toolkit has received your Twitch access token. You may now close this browser window.
</body>
</html>
@@ -0,0 +1,95 @@
var electron = require("electron"),
Chat = require("../../../base/chat"),
Tmi = require("tmi.js"),
TwitchApi = require("twitch-api");

class Twitch extends Chat {
constructor (settings) {
super();

this.settings = settings;

this.api = new TwitchApi(settings.twitch);
}

get connected() {
// TODO: Return whether or not we're connected to TMI.
}

connect() {
var twitch = this;

return new Promise((resolve, reject) => {
var settings;

if (twitch.tmi) {
// TODO: Refine this.
reject("You are already connected.");
return;
}

if (!twitch.authorized) {
reject("You must authorize your Twitch account before connecting.");
return;
}

settings = twitch.settings.tmi;
settings.identity.password = `oauth:${twitch.accessToken}`;

twitch.tmi = new Tmi.client(settings);

twitch.tmi.on("connected", (address, port) => {
twitch.emit("connected", address, port);
});

twitch.tmi.on("message", (channel, userstate, text, self) => {
twitch.emit("message", channel, userstate.username, userstate["display-name"], text);
});

twitch.tmi.connect().then(() => {
twitch.tmi.raw("CAP REQ :twitch.tv/membership");

resolve();
}).catch((err) => {
// TODO: Handle the error more gracefully.
reject(err);
});
});
}

get authorized() {
return !!(this.accessToken);
}

authorize() {
var twitch = this,
api = this.api,
win = new electron.remote.BrowserWindow({width: 800, height: 600, parent: electron.remote.BrowserWindow.getAllWindows().find((w) => w.getTitle() === "Hyperdrive Toolkit"), modal: true, title: "Hyperdrive Toolkit - Waiting for Twitch OAuth"});

return new Promise((resolve, reject) => {
win.loadURL(`file://${__dirname}/twitch.htm`);
win.setMenu(null);

win.once("ready-to-show", () => {
win.show();
});

win.on("access-token", (accessToken) => {
twitch.accessToken = accessToken;
});

win.on("closed", () => {
win = null;
if (twitch.accessToken) {
resolve();
} else {
reject();
}
});

electron.shell.openExternal(api.getAuthorizationUrl().replace("response_type=code", "response_type=token") + "&force_verify=true");
});
}
}

module.exports = Twitch;
@@ -0,0 +1,11 @@
<html>
<head>
<script>
var hash = document.location.hash;
document.location.href = "/token-redirect?" + document.location.hash.substr(1);
</script>
<title>Hyperdrive Toolkit - Twitch OAuth Redirect</title>
</head>
<body>
</body>
</html>
@@ -0,0 +1,17 @@
<html>
<head>
<script src="twitch.js"></script>
<script src="../../../../../node_modules/jquery/dist/jquery.min.js"></script>
<script>$ = jQuery = require("jquery")</script>
<script src="../../../../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link href="../../../../../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"></link>
<link href="../../../../../node_modules/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet"></link>
</head>
<body>
<div class="panel panel-default">
<div class="panel-body">
<div>A browser window has opened for you to authorize Twitch to give access to your account. This window will automatically close when that process is complete.</div>
</div>
</div>
</body>
</html>
@@ -0,0 +1,29 @@
var electron = require("electron"),
express = require("express"),
app = express(),
server, accessToken;

app.use(express.static(`${__dirname}/public`, {index: "index.htm"}));

app.get("/token-redirect", function(req, res) {
accessToken = req.query.access_token;
res.sendFile(`${__dirname}/close.htm`);
electron.remote.getCurrentWindow().emit("access-token", accessToken);
window.close();
});

console.log("Listening on port 65100.");
app.listen(65100);

window.addEventListener("beforeunload", function(ev) {
if (!accessToken) {
if (!confirm("Are you sure you want to exit now?")) {
ev.returnValue = true;
return;
}
}
});

window.addEventListener("unload", function() {
server.close();
});
No changes.

0 comments on commit daf0790

Please sign in to comment.