Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Added Prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalexrouse committed Apr 11, 2024
1 parent 48d4fff commit 45e31d7
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 236 deletions.
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
node_modules/
out/
build/**/*.js
Terabit*/
Terabit*/

dist/
node_modules/
coverage/
npm-debug.log
yarn-error.log
app/node_modules/
.DS_Store
.awcache
.idea/
.vs/
.vscode/*.log
.eslintcache
*.iml
.envrc
junit*.xml
*.swp
tslint-rules/
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build/
content/
node_modules/
src/res/
*.json
**/*.md
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"test": "tsc -p ./src/tsconfig.json && electron .",
"build-win": "electron-packager . --platform=win32 --asar --icon=content/resources/icon --path=out/ --overwrite",
"build-linux": "electron-packager . --platform=linux --asar --icon=content/resources/icon --path=out/ --overwrite",
"ibuild-win": "npm run build-win && electron-installer-windows --src Terabit Desktop-win32-x64/ --icon content/logo.ico --dest out/releases/"
"ibuild-win": "npm run build-win && electron-installer-windows --src Terabit Desktop-win32-x64/ --icon content/logo.ico --dest out/releases/",
"prettier": "prettier --check \"./**/*.{ts,tsx,js}\"",
"prettier-fix": "prettier . --write"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +32,7 @@
"electron-installer-dmg": "^4.0.0",
"electron-installer-windows": "^3.0.0",
"electron-packager": "^17.1.2",
"prettier": "^3.2.5",
"typescript": "^5.4.2"
}
}
79 changes: 42 additions & 37 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
import { app } from 'electron'
import { AssignProtocolHandler } from './tbd/ProtocolHandler';
import { Window } from './tbd/ui/Window';
import { AppInfo, Version } from './tbd/Version';
import {OperatingSystem} from "./tbd/OperatingSystem";
import {Logging} from "./tbd/Logging";
import { app } from "electron";
import { AssignProtocolHandler } from "./tbd/ProtocolHandler";
import { Window } from "./tbd/ui/Window";
import { AppInfo, Version } from "./tbd/Version";
import { OperatingSystem } from "./tbd/OperatingSystem";
import { Logging } from "./tbd/Logging";

let SplashWindow: Window;
let ParentWindow: Window;


app.whenReady().then(() => {
Logging.Info(`Loading: ${AppInfo.APP_NAME} | v${Version.VERSION_MAJOR}.${Version.VERSION_MINOR}.${Version.VERSION_BUILD} - '${Version.VERSION_CODENAME}'...`);
Logging.Info(`Running on '${OperatingSystem.GetHumanFriendlyOS()}' (${OperatingSystem.CurrentArch}).`);
// --------------------------------- Splash Screen ---------------------------------
SplashWindow = new Window(undefined, 620, 300, true);
SplashWindow.Get()?.loadFile(`${__dirname}/splash.html`).catch((result) => {
Logging.Error(`There was an error getting 'splash.html'. ${result}`);
Logging.Info(
`Loading: ${AppInfo.APP_NAME} | v${Version.VERSION_MAJOR}.${Version.VERSION_MINOR}.${Version.VERSION_BUILD} - '${Version.VERSION_CODENAME}'...`,
);
Logging.Info(
`Running on '${OperatingSystem.GetHumanFriendlyOS()}' (${OperatingSystem.CurrentArch}).`,
);
// --------------------------------- Splash Screen ---------------------------------
SplashWindow = new Window(undefined, 620, 300, true);
SplashWindow.Get()
?.loadFile(`${__dirname}/splash.html`)
.catch((result) => {
Logging.Error(`There was an error getting 'splash.html'. ${result}`);
});
// ---------------------------------------------------------------------------------
SplashWindow.Show();
AssignProtocolHandler();
// StartWindow();
ParentWindow = new Window(undefined, 1366, 720);
ParentWindow.Load();
ParentWindow.Show();
SplashWindow.Close();
// ---------------------------------------------------------------------------------
SplashWindow.Show();
AssignProtocolHandler();

// StartWindow();
ParentWindow = new Window(undefined, 1366, 720);
ParentWindow.Load();
ParentWindow.Show();
SplashWindow.Close();
});

app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl)
const allowedOrigins = ['terabit.io', 'discord.com', 'terabit.io:8080']; // Allow Discord for the Discord invite, Allow Terabit.io for the main site and the admin panel.
allowedOrigins.forEach(element => {
if (!parsedUrl.origin.endsWith(element)) {
Logging.Warn(`${element} lead to a URL outside of the allowed origin.`);
event.preventDefault(); // Stops any urls with origins outside terabit.io or discord.com from loading.
}
});
app.on("web-contents-created", (event, contents) => {
contents.on("will-navigate", (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl);
const allowedOrigins = ["terabit.io", "discord.com", "terabit.io:8080"]; // Allow Discord for the Discord invite, Allow Terabit.io for the main site and the admin panel.
allowedOrigins.forEach((element) => {
if (!parsedUrl.origin.endsWith(element)) {
Logging.Warn(`${element} lead to a URL outside of the allowed origin.`);
event.preventDefault(); // Stops any urls with origins outside terabit.io or discord.com from loading.
}
});
});
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
10 changes: 10 additions & 0 deletions src/res/ui/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Terabit Desktop</title>
</head>
<body>
<menu></menu>
</body>
</html>
65 changes: 34 additions & 31 deletions src/tbd/FactorySettings.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import { BrowserWindow, app } from "electron";
const { dialog } = require('electron');
import * as fs from 'fs';
import * as path from 'path';
import {Logging} from "./Logging";
const { dialog } = require("electron");
import * as fs from "fs";
import * as path from "path";
import { Logging } from "./Logging";

export class FactorySettings {
static ResetApplication(): void {
dialog
.showMessageBox(BrowserWindow.getAllWindows()[0], {
type: "warning",
buttons: ["Reset Terabit Desktop", "Cancel"],
defaultId: 0,
title: "Reset Terabit Desktop",
message: "Are you sure you wish to reset Terabit Desktop?",
detail:
"Are you sure you wish to reset Terabit Desktop? You'll need to login again after the reset.",
})
.then((result) => {
if (result.response === 0) {
const getAppPath = path.join(app.getPath("appData"), app.getName());

static ResetApplication(): void {
dialog.showMessageBox(BrowserWindow.getAllWindows()[0], {
type: 'warning',
buttons: ['Reset Terabit Desktop', 'Cancel'],
defaultId: 0,
title: 'Reset Terabit Desktop',
message: 'Are you sure you wish to reset Terabit Desktop?',
detail: "Are you sure you wish to reset Terabit Desktop? You'll need to login again after the reset.",
}).then((result) => {
if (result.response === 0) {
const getAppPath = path.join(app.getPath('appData'), app.getName());
fs.unlink(getAppPath, () => {
Logging.Info(
"The cache has been cleared successfully. We just need to relaunch to apply any needed changes.",
);
app.relaunch();
});
}
});
}

fs.unlink(getAppPath, () => {
Logging.Info("The cache has been cleared successfully. We just need to relaunch to apply any needed changes.");
app.relaunch();
});
}
});
}

public static ResetCache()
{
BrowserWindow.getAllWindows().forEach(element => {
element.webContents.session.clearCache();
element.webContents.reloadIgnoringCache();
});
}
}
public static ResetCache() {
BrowserWindow.getAllWindows().forEach((element) => {
element.webContents.session.clearCache();
element.webContents.reloadIgnoringCache();
});
}
}
22 changes: 16 additions & 6 deletions src/tbd/Logging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { } from 'electron';
import {} from "electron";

export class Logging {
public static Debug(Message: string) { if (process.argv.includes("--verbose")) { console.log(`[DEBUG]: ${Message}`); } }
public static Info(Message: string) { console.log(`[INFO]: ${Message}`); }
public static Warn(Message: string) { console.log(`[WARN]: ${Message}`); }
public static Error(Message: string) { console.log(`[ERROR]: ${Message}`); }
}
public static Debug(Message: string) {
if (process.argv.includes("--verbose")) {
console.log(`[DEBUG]: ${Message}`);
}
}
public static Info(Message: string) {
console.log(`[INFO]: ${Message}`);
}
public static Warn(Message: string) {
console.log(`[WARN]: ${Message}`);
}
public static Error(Message: string) {
console.log(`[ERROR]: ${Message}`);
}
}
33 changes: 16 additions & 17 deletions src/tbd/OperatingSystem.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import process from 'process';
import process from "process";

export class OperatingSystem
{
public static readonly CurrentOS: string = process.platform;
public static readonly CurrentArch: string = process.arch;
export class OperatingSystem {
public static readonly CurrentOS: string = process.platform;
public static readonly CurrentArch: string = process.arch;

public static GetHumanFriendlyOS() {
switch (process.platform) {
case 'win32':
return "Windows";
case 'linux':
return "Linux";
case 'darwin':
return "MacOS";
default:
return "Unknown";
}
public static GetHumanFriendlyOS() {
switch (process.platform) {
case "win32":
return "Windows";
case "linux":
return "Linux";
case "darwin":
return "MacOS";
default:
return "Unknown";
}
}
}
}
20 changes: 10 additions & 10 deletions src/tbd/ProtocolHandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { app } from 'electron';
import path from 'path'
import { app } from "electron";
import path from "path";

export function AssignProtocolHandler()
{
if (process.defaultApp)
if (process.argv.length >= 2)
app.setAsDefaultProtocolClient('terabit', process.execPath, [path.resolve(process.argv[1])])
else
app.setAsDefaultProtocolClient('terabit')
}
export function AssignProtocolHandler() {
if (process.defaultApp)
if (process.argv.length >= 2)
app.setAsDefaultProtocolClient("terabit", process.execPath, [
path.resolve(process.argv[1]),
]);
else app.setAsDefaultProtocolClient("terabit");
}
12 changes: 6 additions & 6 deletions src/tbd/Version.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export class Version {
static VERSION_MAJOR = 1;
static VERSION_MINOR = 0;
static VERSION_BUILD = 1;
static VERSION_CODENAME = "Creek";
static VERSION_MAJOR = 1;
static VERSION_MINOR = 0;
static VERSION_BUILD = 1;
static VERSION_CODENAME = "Creek";
}

export class AppInfo {
static APP_NAME: string = "Terabit Desktop";
}
static APP_NAME: string = "Terabit Desktop";
}
Loading

0 comments on commit 45e31d7

Please sign in to comment.