Skip to content

Commit 81835b1

Browse files
authored
Merge pull request from release/v2.0.0
It's here... Release v2.0.0.
2 parents ce117de + df78264 commit 81835b1

23 files changed

+937
-87
lines changed

.github/workflows/integrate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Test
1+
name: build
22

33
on:
44
push:
@@ -9,7 +9,7 @@ on:
99
branches: [ main ]
1010

1111
jobs:
12-
test_pull_request:
12+
test_build:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v2

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# DEV NOTE:
2+
3+
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.
4+
5+
Since the first line of code, Random Browser was just an experiment and I didn't even plan to update it...
6+
7+
But here we are, Random Browser's last release is out.
8+
9+
This version of Random Browser won't receive new features, just small bug fixes (if any).
10+
11+
Note how I said "this version", though. I've been planning to migrate the entire projet to a different framework or programming language.
12+
13+
We'll see...
14+
115
<div align="center" style="display:flex;flex-direction:column;">
216
<h1>Random Browser</h1>
317

@@ -40,7 +54,7 @@ Once everything is installed, build the typescript code:
4054
```bash
4155
yarn build
4256
```
43-
**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.**
57+
4458

4559
And **you're done**! Now run:
4660
```bash
@@ -75,7 +89,6 @@ Once everything is installed, build the typescript code:
7589
```bash
7690
yarn build
7791
```
78-
**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.**
7992

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

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

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

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

109122
## Contributing setup
110-
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:
123+
> **<!>** 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.
111124
112-
- **USE** Yarn
113-
- Make sure to exclude any file that shouldn't be uploaded to github.
125+
<!-- TODO: Create the contributing file -->
126+
Before you can get to contributing, please read the `contributing` file.
114127

115128
# License
116129
<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>.

changelog.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[2.0.0] => {
2+
Features => {
3+
[DONE] Custom App Frame.
4+
[DONE] New Tab System.
5+
[DONE] Initial App Loader.
6+
[DONE] Download Progress Bar.
7+
[DELAYED->v3.0.0] New Settings Menu.
8+
}
9+
Fixes => {
10+
[DONE] Fixed Random Browser's Page Link.
11+
}
12+
}

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
"private": true,
33
"name": "random-browser",
44
"productName": "Random Browser",
5-
"version": "1.2.2",
5+
"version": "2.0.0",
66
"description": "Just a random browser...",
77
"main": "build/index.js",
88
"scripts": {
99
"start": "cp -r ./src/public ./build && electron build/index.js",
1010
"build": "tsc",
1111
"start:dev": "nodemon build/index.js",
1212
"build:dev": "tsc -w",
13-
"pack-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/icon.icns --prune=true --out=dist",
14-
"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\"",
15-
"pack-linux": "electron-packager . random-browser --overwrite --asar=false --platform=linux --arch=x64 --icon=assets/icons/1024x1024.png --prune=true --out=dist"
13+
"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\""
1614
},
1715
"repository": "https://github.com/YisusGaming/random-browser",
1816
"author": "YisusGaming",
@@ -22,6 +20,7 @@
2220
},
2321
"devDependencies": {
2422
"electron-packager": "^17.1.1",
25-
"nodemon": "^2.0.20"
23+
"nodemon": "^2.0.20",
24+
"typescript": "^4.9.5"
2625
}
2726
}

src/config/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "v1.2.2"
2+
"version": "v2.0.0"
33
}

src/index.ts

Lines changed: 95 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,100 @@
1-
import { app, BrowserWindow, ipcMain, Menu, MenuItemConstructorOptions } from 'electron';
1+
import { app, BrowserWindow, ipcMain, Menu } from 'electron';
2+
import Logger from './logs/Logger.js';
3+
import TabManager from './tabs/TabManager.js';
24
import configs from './config/app.json';
35
import './config/user.json';
46
import fs from 'fs';
57
import path from 'path';
68

7-
const publicPath = path.join(__dirname, 'public');
9+
// Instance of the logger class for future console logs.
10+
// Also exports the instance for use in other files
11+
// without the need to reinstance the class again.
12+
export const logger = new Logger(configs.version);
13+
14+
export const publicPath = path.join(__dirname, 'public');
815
const userConfigPath = path.join(__dirname, 'config', 'user.json');
9-
console.log(`Looking for user's configs in ${userConfigPath}`);
16+
// console.log(`Looking for user's configs in ${userConfigPath}`);
17+
logger.logMessage(`Looking for user's configs in ${userConfigPath}`);
1018

1119
let main : BrowserWindow;
12-
let searchWin : BrowserWindow;
20+
let tabModal : BrowserWindow;
1321
let backgroundSelect : BrowserWindow;
22+
let appLoader : BrowserWindow;
1423
app.on('ready', () => {
24+
logger.logMessage(`App is ready.`);
25+
spawnAppLoader();
1526
main = new BrowserWindow({
1627
title: 'Random Browser - Loading...',
1728
webPreferences: {
1829
nodeIntegration: true,
1930
contextIsolation: false
2031
},
32+
frame: false,
2133
show: false
2234
});
35+
// ! Make sure to set the application menu to null in production.
2336
Menu.setApplicationMenu(null);
2437
main.loadFile(path.join(publicPath, 'index.html'));
2538
main.on('ready-to-show', () => {
39+
logger.logMessage(`Main window ready to show.`);
2640
main.show();
27-
main.maximize();
41+
// ! Make sure to destoy appLoader in production.
42+
appLoader.destroy();
2843

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

3247
main.webContents.send('update-background', configs.background);
3348
});
34-
main.on('close', () => {
35-
if (backgroundSelect != null) {
36-
try {
37-
backgroundSelect.close();
38-
} catch(err) {
39-
console.log(`[FAILED] close background select window [->] ${err}.`);
40-
}
41-
}
42-
});
4349
});
4450

45-
function searchWindow(url: string) {
46-
searchWin = new BrowserWindow({
47-
title: `Searching ${url}...`,
48-
minimizable: false
49-
});
50-
searchWin.loadURL(url);
51+
/**
52+
* Works as a *bridge* or *gateway* that allows communication with main's webCotents.
53+
* @param event The event that will be send to main via `webContents.send`
54+
*
55+
* @throws {EvalError} if the string passed as event is empty.
56+
*/
57+
export function mainWindowGateway(event: string, ...args: any[]): void {
58+
logger.tempLogMessage(`Main Gateway used, event: ${event}`);
59+
if (event.trim() == '') throw new EvalError("Event cannot be empty.");
60+
61+
main.webContents.send(event, args);
62+
}
5163

52-
const menuTemplate: Array<MenuItemConstructorOptions> = [
53-
{
54-
label: 'Refresh',
55-
role: 'reload'
64+
function spawnAppLoader() {
65+
logger.logMessage("App loader spawned.");
66+
appLoader = new BrowserWindow({
67+
webPreferences: {
68+
nodeIntegration: true,
69+
contextIsolation: false
5670
},
57-
{
58-
label: 'Inspect',
59-
role: 'toggleDevTools'
60-
}
61-
]
71+
title: 'Random Browser - Loading...',
72+
frame: false,
73+
closable: false,
74+
maximizable: false,
75+
resizable: false,
76+
height: 400,
77+
width: 320
78+
});
79+
appLoader.loadFile(path.join(publicPath, 'loader.html'));
80+
appLoader.on('closed', () => {
81+
logger.logMessage("App loader closed.");
82+
main.flashFrame(true);
83+
});
84+
}
6285

63-
searchWin.setMenu(Menu.buildFromTemplate(menuTemplate));
86+
/**
87+
* Createsa a Tab and builds it.
88+
* Tabs will show up once they're built.
89+
*/
90+
export function spawnTab(url: string) {
91+
tabModal = TabManager.createTab(url, main).build();
6492
}
6593

94+
/**
95+
* Spawns a Browser Window for the user to select a custom
96+
* background.
97+
*/
6698
function selectBackground() {
6799
backgroundSelect = new BrowserWindow({
68100
title: "Change Browser's Background",
@@ -71,26 +103,49 @@ function selectBackground() {
71103
contextIsolation: false
72104
},
73105
minimizable: false,
74-
maximizable: false
106+
maximizable: false,
107+
parent: main
75108
});
76109
backgroundSelect.setMenu(null);
77110
backgroundSelect.loadFile(path.join(publicPath, 'background.html'));
78111
}
79112

80-
/* IPC */
113+
ipcMain.on('minimize-main', (event) => {
114+
// Minimize the main window
115+
main.minimize();
116+
});
117+
118+
ipcMain.on('maximize-main', (event) => {
119+
// Maximize the main window
120+
main.maximize();
121+
});
122+
123+
ipcMain.on('close-main', (event) => {
124+
// Close the main window
125+
main.close();
126+
});
127+
128+
ipcMain.on('open-tab', (event, tabId: number) => {
129+
TabManager.openTab(tabId);
130+
});
131+
132+
ipcMain.on('tab-deleted', (event, tabId: number) => {
133+
TabManager.deleteTab(tabId);
134+
});
135+
81136
ipcMain.on('new-search', (event, search: string) => {
82137
if (search.trim() == '') return;
83138

84139
if (/[*.*]/g.test(search)) {
85140
if (search.startsWith('https://') || search.startsWith('http://')) {
86-
searchWindow(search);
141+
spawnTab(search);
87142
return;
88143
}
89-
searchWindow(`https://${search}`);
144+
spawnTab(`https://${search}`);
90145
return;
91146
}
92147

93-
searchWindow(`https://google.com/search?q=${search}`);
148+
spawnTab(`https://google.com/search?q=${search}`);
94149
});
95150

96151
ipcMain.on('new-background-image', (event) => {
@@ -126,4 +181,8 @@ ipcMain.on('clear-background', (event) => {
126181
backgroundSelect.close();
127182
main.webContents.send('update-background', '');
128183
main.loadFile(path.join(publicPath, 'index.html'));
129-
});
184+
});
185+
186+
ipcMain.on('minimize-apploader', (event) => {
187+
appLoader.minimize();
188+
});

src/logs/Logger.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* The logger class.
3+
* @since v2.0.0
4+
*
5+
* Prints messages to `stdout` and `stderr`.
6+
*/
7+
export default class Logger {
8+
private browserVersion: string;
9+
10+
/**
11+
* @param browserVersion Random Browser's current version allocated in `app.json`
12+
*/
13+
constructor(browserVersion: string) {
14+
this.browserVersion = browserVersion;
15+
}
16+
17+
/**
18+
* Prints a message to the `stdout`.
19+
*/
20+
logMessage(msg: string): void {
21+
console.log(`[LOG:${this.browserVersion}] => ${msg}`);
22+
}
23+
24+
/**
25+
* Prints a message to the `stdout` with a label
26+
* saying it should be removed before the app
27+
* gets to production.
28+
*/
29+
tempLogMessage(msg: string): void {
30+
console.log(`The following log is temporal and should be removed before production.\n[TEMPORAL LOG:${this.browserVersion}] => ${msg}`);
31+
}
32+
33+
/**
34+
* Prints a warning to the `stderr`.
35+
*/
36+
logWarning(warn: string): void {
37+
console.warn(`[WARNING!] => ${warn} | ${this.browserVersion}`);
38+
}
39+
40+
/**
41+
* Prints an `string` or an `Error` to `stderr`.
42+
*/
43+
logError(err: string | Error, origin: { file: string }): void {
44+
if (typeof err == 'string') {
45+
console.error(
46+
`[ERR!] => ${err} | ${this.browserVersion} [${origin.file}]`
47+
);
48+
} else {
49+
console.error(
50+
`[ERR!] => ${err.name}: ${err.message} | ${this.browserVersion} [${origin.file}]`
51+
);
52+
}
53+
}
54+
}

src/public/assets/icon/icon.ico

16.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)