Skip to content

Commit

Permalink
Merge pull request from release/v2.0.0
Browse files Browse the repository at this point in the history
It's here... Release v2.0.0.
  • Loading branch information
YisusGaming authored Dec 23, 2023
2 parents ce117de + df78264 commit 81835b1
Show file tree
Hide file tree
Showing 23 changed files with 937 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Test
name: build

on:
push:
Expand All @@ -9,7 +9,7 @@ on:
branches: [ main ]

jobs:
test_pull_request:
test_build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# DEV NOTE:

Hey! It's been a long while since I last updated Random Browser. It's currently December 23th 2023, v2.0.0 is finally out, or at least, it'll be soon.

Since the first line of code, Random Browser was just an experiment and I didn't even plan to update it...

But here we are, Random Browser's last release is out.

This version of Random Browser won't receive new features, just small bug fixes (if any).

Note how I said "this version", though. I've been planning to migrate the entire projet to a different framework or programming language.

We'll see...

<div align="center" style="display:flex;flex-direction:column;">
<h1>Random Browser</h1>

Expand Down Expand Up @@ -40,7 +54,7 @@ Once everything is installed, build the typescript code:
```bash
yarn build
```
**NOTE: typescript is not listed as a dependency in package.json. It should be installed globally on your computer, if not, you can install it globally or in the cloned repository.**


And **you're done**! Now run:
```bash
Expand Down Expand Up @@ -75,7 +89,6 @@ Once everything is installed, build the typescript code:
```bash
yarn build
```
**NOTE: typescript is not listed as a dependency in package.json. It should be installed globally on your computer, if not, you can install it globally or in the cloned repository.**

Now, you have to run the project from the command line before packaging, just run:

Expand All @@ -87,7 +100,7 @@ When you do that, the public folder (where all resources for views are) will be

> If something goes wrong, you can copy the folder manually. Just copy **./src/public/** to **./build/**
Once this is done and the browser's window is now open, you can close the browser and finally package the app:
Once this is done and the browser's window is open, you can close the browser and finally package the app:

For Windows:
```bash
Expand All @@ -107,10 +120,10 @@ yarn pack-mac
When that's finished, you should see a folder named **dist**, inside of it you can find executable.

## Contributing setup
Sorry, this setup is not documented yet and neither is the project's code. You can follow the [development setup](#development-setup), just make sure to follow these rules:
> **<!>** Currently the project's code is not so well documented as I'd like. I'll be working on documenting everything better so contributors can more easily understand what the code is doing. If you'd like to contribute, I'm glad having your help on this project, just know that it may be a little confusing for now.
- **USE** Yarn
- Make sure to exclude any file that shouldn't be uploaded to github.
<!-- TODO: Create the contributing file -->
Before you can get to contributing, please read the `contributing` file.

# License
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">Random Browser</span> by <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName">YisusGaming</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License</a>.
12 changes: 12 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[2.0.0] => {
Features => {
[DONE] Custom App Frame.
[DONE] New Tab System.
[DONE] Initial App Loader.
[DONE] Download Progress Bar.
[DELAYED->v3.0.0] New Settings Menu.
}
Fixes => {
[DONE] Fixed Random Browser's Page Link.
}
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"private": true,
"name": "random-browser",
"productName": "Random Browser",
"version": "1.2.2",
"version": "2.0.0",
"description": "Just a random browser...",
"main": "build/index.js",
"scripts": {
"start": "cp -r ./src/public ./build && electron build/index.js",
"build": "tsc",
"start:dev": "nodemon build/index.js",
"build:dev": "tsc -w",
"pack-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/icon.icns --prune=true --out=dist",
"pack-win": "electron-packager . random-browser --overwrite --asar=false --platform=win32 --arch=ia32 --icon=assets/icons/icon.ico --prune=true --out=dist --version-string.CompanyName=YisusGaming --version-string.FileDescription=\"Just a random browser...\" --version-string.ProductName=\"Random Browser\"",
"pack-linux": "electron-packager . random-browser --overwrite --asar=false --platform=linux --arch=x64 --icon=assets/icons/1024x1024.png --prune=true --out=dist"
"pack-win": "electron-packager . random-browser --overwrite --asar=false --platform=win32 --arch=ia32 --icon=assets/icons/icon.ico --prune=true --out=dist --version-string.CompanyName=YisusGaming --version-string.FileDescription=\"Just a random browser...\" --version-string.ProductName=\"Random Browser\""
},
"repository": "https://github.com/YisusGaming/random-browser",
"author": "YisusGaming",
Expand All @@ -22,6 +20,7 @@
},
"devDependencies": {
"electron-packager": "^17.1.1",
"nodemon": "^2.0.20"
"nodemon": "^2.0.20",
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion src/config/app.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v1.2.2"
"version": "v2.0.0"
}
131 changes: 95 additions & 36 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,100 @@
import { app, BrowserWindow, ipcMain, Menu, MenuItemConstructorOptions } from 'electron';
import { app, BrowserWindow, ipcMain, Menu } from 'electron';
import Logger from './logs/Logger.js';
import TabManager from './tabs/TabManager.js';
import configs from './config/app.json';
import './config/user.json';
import fs from 'fs';
import path from 'path';

const publicPath = path.join(__dirname, 'public');
// Instance of the logger class for future console logs.
// Also exports the instance for use in other files
// without the need to reinstance the class again.
export const logger = new Logger(configs.version);

export const publicPath = path.join(__dirname, 'public');
const userConfigPath = path.join(__dirname, 'config', 'user.json');
console.log(`Looking for user's configs in ${userConfigPath}`);
// console.log(`Looking for user's configs in ${userConfigPath}`);
logger.logMessage(`Looking for user's configs in ${userConfigPath}`);

let main : BrowserWindow;
let searchWin : BrowserWindow;
let tabModal : BrowserWindow;
let backgroundSelect : BrowserWindow;
let appLoader : BrowserWindow;
app.on('ready', () => {
logger.logMessage(`App is ready.`);
spawnAppLoader();
main = new BrowserWindow({
title: 'Random Browser - Loading...',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
frame: false,
show: false
});
// ! Make sure to set the application menu to null in production.
Menu.setApplicationMenu(null);
main.loadFile(path.join(publicPath, 'index.html'));
main.on('ready-to-show', () => {
logger.logMessage(`Main window ready to show.`);
main.show();
main.maximize();
// ! Make sure to destoy appLoader in production.
appLoader.destroy();

const rawConfig = fs.readFileSync(userConfigPath, { encoding: 'utf-8' });
const configs = JSON.parse(rawConfig);

main.webContents.send('update-background', configs.background);
});
main.on('close', () => {
if (backgroundSelect != null) {
try {
backgroundSelect.close();
} catch(err) {
console.log(`[FAILED] close background select window [->] ${err}.`);
}
}
});
});

function searchWindow(url: string) {
searchWin = new BrowserWindow({
title: `Searching ${url}...`,
minimizable: false
});
searchWin.loadURL(url);
/**
* Works as a *bridge* or *gateway* that allows communication with main's webCotents.
* @param event The event that will be send to main via `webContents.send`
*
* @throws {EvalError} if the string passed as event is empty.
*/
export function mainWindowGateway(event: string, ...args: any[]): void {
logger.tempLogMessage(`Main Gateway used, event: ${event}`);
if (event.trim() == '') throw new EvalError("Event cannot be empty.");

main.webContents.send(event, args);
}

const menuTemplate: Array<MenuItemConstructorOptions> = [
{
label: 'Refresh',
role: 'reload'
function spawnAppLoader() {
logger.logMessage("App loader spawned.");
appLoader = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
{
label: 'Inspect',
role: 'toggleDevTools'
}
]
title: 'Random Browser - Loading...',
frame: false,
closable: false,
maximizable: false,
resizable: false,
height: 400,
width: 320
});
appLoader.loadFile(path.join(publicPath, 'loader.html'));
appLoader.on('closed', () => {
logger.logMessage("App loader closed.");
main.flashFrame(true);
});
}

searchWin.setMenu(Menu.buildFromTemplate(menuTemplate));
/**
* Createsa a Tab and builds it.
* Tabs will show up once they're built.
*/
export function spawnTab(url: string) {
tabModal = TabManager.createTab(url, main).build();
}

/**
* Spawns a Browser Window for the user to select a custom
* background.
*/
function selectBackground() {
backgroundSelect = new BrowserWindow({
title: "Change Browser's Background",
Expand All @@ -71,26 +103,49 @@ function selectBackground() {
contextIsolation: false
},
minimizable: false,
maximizable: false
maximizable: false,
parent: main
});
backgroundSelect.setMenu(null);
backgroundSelect.loadFile(path.join(publicPath, 'background.html'));
}

/* IPC */
ipcMain.on('minimize-main', (event) => {
// Minimize the main window
main.minimize();
});

ipcMain.on('maximize-main', (event) => {
// Maximize the main window
main.maximize();
});

ipcMain.on('close-main', (event) => {
// Close the main window
main.close();
});

ipcMain.on('open-tab', (event, tabId: number) => {
TabManager.openTab(tabId);
});

ipcMain.on('tab-deleted', (event, tabId: number) => {
TabManager.deleteTab(tabId);
});

ipcMain.on('new-search', (event, search: string) => {
if (search.trim() == '') return;

if (/[*.*]/g.test(search)) {
if (search.startsWith('https://') || search.startsWith('http://')) {
searchWindow(search);
spawnTab(search);
return;
}
searchWindow(`https://${search}`);
spawnTab(`https://${search}`);
return;
}

searchWindow(`https://google.com/search?q=${search}`);
spawnTab(`https://google.com/search?q=${search}`);
});

ipcMain.on('new-background-image', (event) => {
Expand Down Expand Up @@ -126,4 +181,8 @@ ipcMain.on('clear-background', (event) => {
backgroundSelect.close();
main.webContents.send('update-background', '');
main.loadFile(path.join(publicPath, 'index.html'));
});
});

ipcMain.on('minimize-apploader', (event) => {
appLoader.minimize();
});
54 changes: 54 additions & 0 deletions src/logs/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* The logger class.
* @since v2.0.0
*
* Prints messages to `stdout` and `stderr`.
*/
export default class Logger {
private browserVersion: string;

/**
* @param browserVersion Random Browser's current version allocated in `app.json`
*/
constructor(browserVersion: string) {
this.browserVersion = browserVersion;
}

/**
* Prints a message to the `stdout`.
*/
logMessage(msg: string): void {
console.log(`[LOG:${this.browserVersion}] => ${msg}`);
}

/**
* Prints a message to the `stdout` with a label
* saying it should be removed before the app
* gets to production.
*/
tempLogMessage(msg: string): void {
console.log(`The following log is temporal and should be removed before production.\n[TEMPORAL LOG:${this.browserVersion}] => ${msg}`);
}

/**
* Prints a warning to the `stderr`.
*/
logWarning(warn: string): void {
console.warn(`[WARNING!] => ${warn} | ${this.browserVersion}`);
}

/**
* Prints an `string` or an `Error` to `stderr`.
*/
logError(err: string | Error, origin: { file: string }): void {
if (typeof err == 'string') {
console.error(
`[ERR!] => ${err} | ${this.browserVersion} [${origin.file}]`
);
} else {
console.error(
`[ERR!] => ${err.name}: ${err.message} | ${this.browserVersion} [${origin.file}]`
);
}
}
}
Binary file added src/public/assets/icon/icon.ico
Binary file not shown.
Loading

0 comments on commit 81835b1

Please sign in to comment.