Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Fixed issues with building
Browse files Browse the repository at this point in the history
  • Loading branch information
FusionSid committed Jul 27, 2022
1 parent 5da958a commit e368d72
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 36 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\"",
"build-css": "tailwindcss build -i src/assets/tailwindcss/input.css -o src/assets/tailwindcss/styles.css --watch",
"build-osx": "electron-packager ./ --platform darwin --out ./dist --overwrite"
"build-osx": "electron-packager ./ untitled-chat-app --platform darwin --out ./dist/mac --overwrite",
"build-windows": "electron-packager ./ untitled-chat-app --overwrite --asar=true --platform=win32 --arch=ia32 --prune=true --out ./dist/windows --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName='Unititled Chat'",
"build-linux": "electron-packager ./ untitled-chat-app --overwrite --asar=true --platform=linux --arch=x64 --prune=true --out ./dist/linux"
},
"keywords": [],
"author": {
Expand Down
59 changes: 59 additions & 0 deletions src/html/create_room.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="../assets/styles/login.css">
</head>

<body>
<div style="height: 15vh;"></div>
<div class="login-form">
<p id="alert" style="color: red;"></p>
<h1>Create new room</h1>
<form>
<label for="room_name">Room Name:</label><br>
<input class="text-input" type="text" id="room_name" name="room_name" placeholder="Rickrollers" required><br>

<br>

<label for="description">Room Description:</label><br>
<input class="text-input" type="text" id="description" name="description" placeholder="For people who like rickrolling"><br><br>

<input class="submit-button" type="submit" value="Create Room">
</form>
</div>

<script>
const { ipcRenderer } = require("electron");

const form = document.querySelector("form")

function submition(event) {
event.preventDefault();

var room_name = document.querySelector("#room_name")
var room_description = document.querySelector("#description")

data = {
room_name: room_name.value,
room_description: room_description.value
}

// Reset values
room_name.value = ""
room_description.value = ""

ipcRenderer.invoke("new-room-create:create_room", data).then((data) => {
const alertP = document.getElementById("alert")
alertP.innerHTML = data
});

}

form.addEventListener("submit", submition);
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion src/html/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ <h1>Login to the app</h1>
</script>
</body>

</html>
</html>
15 changes: 15 additions & 0 deletions src/html/signed_in.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ <h1>What would you like to do?</h1>
<span>Sign Out</span>
</button>
</form>

<form id="create-room-button" class="sl-button">
<button>
<span>Create Room</span>
</button>
</form>
</div>

<script>
Expand All @@ -52,6 +58,15 @@ <h1>What would you like to do?</h1>
}

form2.addEventListener("submit", submition2);

const form3 = document.querySelector("#create-room-button")

function submition3(event) {
event.preventDefault();
ipcRenderer.send("create-room:signed_in");
}

form3.addEventListener("submit", submition3);
</script>
</body>

Expand Down
71 changes: 46 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {
signupUser,
getUserWithToken,
updateUserDetails,
getRoomById
getRoomById,
createNewRoom,
} = require("./scripts/requests");
const {
firstTimeUserPage,
Expand All @@ -26,6 +27,7 @@ const {
createSignupWindow,
createRoomWindow,
createEnterRoomIDWindow,
createNewRoomWindow,
} = require("./scripts/windows");
const mainWindowMenuTemplate = require("./scripts/menu");

Expand All @@ -38,7 +40,7 @@ if (require("electron-squirrel-startup")) {
require("dotenv").config();

/* Constants */
const API_URL = process.env.API_URL;
const API_URL = "https://chatapi.fusionsid.xyz";
const mainMenu = Menu.buildFromTemplate(mainWindowMenuTemplate);
Menu.setApplicationMenu(mainMenu);

Expand All @@ -48,7 +50,13 @@ const store = new Store();
global.app = app;

// Define for later
let firstTimeUserPageWindow, loginWindow, signupWindow, signedInWindow, enterRoomIDWindow, roomWindow;
let firstTimeUserPageWindow,
loginWindow,
signupWindow,
signedInWindow,
enterRoomIDWindow,
roomWindow,
newRoomWindow;

/* Electron App Events: */

Expand Down Expand Up @@ -91,9 +99,14 @@ app.on("window-all-closed", () => {
});

// If no windows are open launch one
app.on("activate", () => {
app.on("activate", async () => {
if (BrowserWindow.getAllWindows().length === 0) {
firstTimeUserPageWindow = firstTimeUserPage();
let isFirstTimeUser = await checkIfFirstTimeUser();
if (isFirstTimeUser) {
signedInWindow = createSignedInWindow();
} else {
firstTimeUserPageWindow = firstTimeUserPage();
}
}
});

Expand Down Expand Up @@ -124,10 +137,7 @@ ipcMain.handle("new-login:login", async function (event, data) {

store.set("private_key", privateKey);

let user = await getUserWithToken();
let user_id = user.id;

await updateUserDetails(user_id, "public_key", publicKey);
await updateUserDetails("public_key", publicKey);

loginWindow.close();
loginWindow = null;
Expand Down Expand Up @@ -163,45 +173,56 @@ ipcMain.on("sign-out:signed_in", async function (event) {
ipcMain.on("join-room-window:signed_in", async function (event) {
signedInWindow.close();
signedInWindow = null;
enterRoomIDWindow = createEnterRoomIDWindow()
enterRoomIDWindow = createEnterRoomIDWindow();
});


ipcMain.handle("join-new-room:join_room", async function (event, room_id) {
let room = null;
try {
room = await getRoomById(room_id)
room = await getRoomById(room_id);
} catch (e) {
console.log("Skill gap")
console.log("Skill gap");
}
if (room === null || room === undefined) {
return "Room not found (lil' dif in skill level ngl)"
return "Room not found (lil' dif in skill level ngl)";
}
enterRoomIDWindow.close()
enterRoomIDWindow.close();
enterRoomIDWindow = null;

connect_to_room(room.room_id)
connect_to_room(room.room_id);
});


// The real stuff
async function connect_to_room(room_id) {
let access_token = await getAccessToken(
store.get("username"),
store.get("password")
);

roomWindow = createRoomWindow()
roomWindow = createRoomWindow();

ipcMain.handle("gimme-connection:room", async function (event) {
let user = await getUserWithToken(access_token)
let room_data = await getRoomById(room_id)
let user = await getUserWithToken(access_token);
let room_data = await getRoomById(room_id);
data = {
user: user,
access_token: access_token,
room_data: room_data,
}
return data
})

}
};
return data;
});
}

ipcMain.on("create-room:signed_in", function (event) {
signedInWindow.close();
signedInWindow = null;
newRoomWindow = createNewRoomWindow();
});

ipcMain.handle("new-room-create:create_room", async function (event, data) {
let room_id;
console.log(data);
room = await createNewRoom(data.room_name, data.room_description);
room_id = room.room_id;
return `Room created successfully: ${room_id}`;
});
34 changes: 27 additions & 7 deletions src/scripts/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { URLSearchParams } = require("url");

const store = new Store();
require("dotenv").config();
const API_URL = process.env.API_URL;
const API_URL = "https://chatapi.fusionsid.xyz";

async function getAccessToken(username = null, password = null, admin = false) {
let token;
Expand Down Expand Up @@ -38,8 +38,6 @@ async function getAccessToken(username = null, password = null, admin = false) {
}

async function signupUser(data) {
let access_token = await getAccessToken(null, null, (admin = true));

let keys = new rsa().generateKeyPair();
let publicKey = keys.exportKey("public");
let privateKey = keys.exportKey("private");
Expand All @@ -51,7 +49,6 @@ async function signupUser(data) {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${access_token}`,
},
body: JSON.stringify({
username: data.username,
Expand Down Expand Up @@ -86,10 +83,10 @@ async function getUserWithToken(token) {
return data;
}

async function updateUserDetails(user_id, attribute, new_value) {
let access_token = await getAccessToken(null, null, (admin = true));
async function updateUserDetails(attribute, new_value) {
let access_token = await getAccessToken(store.get("password"), store.get("username"));

await fetch(`${API_URL}/api/users/${user_id}`, {
await fetch(`${API_URL}/api/user/me`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Expand All @@ -108,6 +105,28 @@ async function updateUserDetails(user_id, attribute, new_value) {
return data;
}

async function createNewRoom(room_name, room_description=null) {
let access_token = await getAccessToken(store.get("username"), store.get("password"));

await fetch(`${API_URL}/api/chatroom/new`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${access_token}`,
},
body: JSON.stringify({
room_name: room_name,
room_description: room_description,
}),
})
.then((response) => response.json())
.then((json_data) => {
data = json_data;
});

return data;
}

async function getRoomById(room_id) {
let access_token = await getAccessToken(
store.get("username"),
Expand All @@ -134,6 +153,7 @@ module.exports = {
signupUser,
getUserWithToken,
updateUserDetails,
createNewRoom,
getRoomById,
};

Expand Down
27 changes: 25 additions & 2 deletions src/scripts/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ Menu.setApplicationMenu(mainMenu);
/* Window Creation */

// Define for later because JS IS WEIRD AF
let firstTimeWindow, loginWindow, signedInWindow, signupWindow, enterRoomIDWindow, roomWindow;
let firstTimeWindow,
loginWindow,
signedInWindow,
signupWindow,
enterRoomIDWindow,
roomWindow,
newRoomWindow;

// Creates first time user page, Launched if first time opening
function firstTimeUserPage() {
Expand All @@ -27,6 +33,22 @@ function firstTimeUserPage() {
return firstTimeWindow;
}

function createNewRoomWindow() {
newRoomWindow = new BrowserWindow({
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
},
width: 1300,
height: 760,
});

// load in index.html file
newRoomWindow.loadFile(path.join(__dirname, "../html/create_room.html"));

return newRoomWindow;
}

function createLoginWindow() {
loginWindow = new BrowserWindow({
webPreferences: {
Expand Down Expand Up @@ -113,5 +135,6 @@ module.exports = {
createSignedInWindow,
createSignupWindow,
createEnterRoomIDWindow,
createRoomWindow
createRoomWindow,
createNewRoomWindow
};

0 comments on commit e368d72

Please sign in to comment.