Skip to content

Commit

Permalink
0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cymmer committed Jan 19, 2022
1 parent c81bf57 commit 12be06f
Show file tree
Hide file tree
Showing 7 changed files with 5,606 additions and 4,091 deletions.
2 changes: 1 addition & 1 deletion release/app/package-lock.json

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

2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codechum",
"version": "0.4.1",
"version": "0.4.2",
"main": "./dist/main/main.js",
"scripts": {
"electron-rebuild": "node -r ts-node/register ../../.erb/scripts/electron-rebuild.js",
Expand Down
4,310 changes: 2,189 additions & 2,121 deletions release/app/yarn.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main/dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
provider: generic
url: 'http://localhost/release'
270 changes: 172 additions & 98 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';

import { BrowserWindow, app, ipcMain, shell } from 'electron';
import { exec, spawn } from 'child_process';
import { BrowserWindow, app, shell } from 'electron';
import axios, { AxiosError } from 'axios';

import { AppImageUpdater } from 'electron-updater';
// eslint-disable-next-line import/order
import MenuBuilder from './menu';
/**
* This module executes inside of electron's main process. You can start
* electron renderer process from here and communicate with the other processes
* through IPC.
*
* When running `npm run build` or `npm run build:main`, this file is compiled to
* `./src/main.js` using webpack. This gives us some performance wins.
*/
import axios from 'axios';
// eslint-disable-next-line import/order
import { version as currentAppVersion } from '../../release/app/package.json';
// eslint-disable-next-line import/order
import log from 'electron-log';
// eslint-disable-next-line import/order
import path from 'path';
import { resolveHtmlPath } from './util';
import { update } from 'lodash';

let mainWindow: BrowserWindow | null = null;
const controller = new AbortController();
const { signal } = controller;
const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');

/**
* AutoUpdate Settings
*/
const autoUpdater = new AppImageUpdater();
autoUpdater.autoDownload = false; // We allow users to choose whether to download or not
// assuming the update is optional
autoUpdater.autoInstallOnAppQuit = false; // set to `true` if there is a crucial update
autoUpdater.checkForUpdatesAndNotify();

/**
* Environment Settings
*/
if (process.env.NODE_ENV === 'production') {
const sourceMapSupport = require('source-map-support');
sourceMapSupport.install();
}

const isDevelopment =
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';

Expand All @@ -56,14 +58,22 @@ const installExtensions = async () => {
.catch(console.log);
};

/**
* Utility Functions
*/
const sendStatusToWindow = (text: string) => {
log.info(text);
mainWindow?.webContents.send('message', text);
};

/**
* Main Processes
*/
const createWindow = async () => {
if (isDevelopment) {
await installExtensions();
}

const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');
const getAssetPath = (...paths: string[]): string => {
return path.join(RESOURCES_PATH, ...paths);
};
Expand All @@ -80,101 +90,168 @@ const createWindow = async () => {
webSecurity: false,
},
});
mainWindow?.loadURL(resolveHtmlPath('index.html'));

function sendStatusToWindow(text: string) {
log.info(text);
mainWindow!.webContents.send('message', text);
}

autoUpdater.on('checking-for-update', () => {
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: `AutoUpdater: Checking for update.` }
);
sendStatusToWindow('Checking for update...');
const updateWindow = new BrowserWindow({
width: 800,
height: 600,
parent: mainWindow,
show: false,
});
updateWindow.loadURL('https://github.com');

let updateAvailable = false;
const win = new BrowserWindow({
// DUMMY
const dummyWindow = new BrowserWindow({
width: 800,
height: 600,
parent: mainWindow,
show: false,
});
win.loadURL('https://github.com');
autoUpdater.on('update-available', (info: any) => {
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: `AutoUpdater: Update available.` + info }
);
sendStatusToWindow('Update available.');
updateAvailable = true;
});
dummyWindow.loadURL('https://google.com');

autoUpdater.on('update-not-available', (info: any) => {
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: `Update not available: ` + info }
);
sendStatusToWindow('Update not available.');
});
autoUpdater.on('error', (err: string) => {
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: `AutoUpdater: Error in auto-updater: ` + err }
);
sendStatusToWindow('Error in auto-updater. ' + err);
});
autoUpdater.on(
'download-progress',
(progressObj: {
bytesPerSecond: string;
percent: string;
transferred: string;
total: string;
}) => {
let log_message = 'Download speed: ' + progressObj.bytesPerSecond;
mainWindow?.on('ready-to-show', async () => {
let hasInternet = true;

// Check Internet
try {
await axios.get('https://google.com');
} catch (error: unknown) {
// const err = error as AxiosError;
// For debugging
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: log_message + ' - Downloaded ' + progressObj.percent + '%' }
{
content: `internet: hi`,
}
);
hasInternet = false;
}

if (!hasInternet) {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.show();
}
return;
}

if (isDevelopment) return;
// Check for updates
let updates;
try {
updates = await autoUpdater.checkForUpdates();
console.log(`UPDATES: ${JSON.stringify(updates)}`);
axios.post(
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{
content: `updates: ${JSON.stringify(updates)}`,
}
);
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
log_message =
log_message +
' (' +
progressObj.transferred +
'/' +
progressObj.total +
')';
sendStatusToWindow(log_message);
// eslint-disable-next-line no-empty
} catch (e) {
console.log(`UPDATES error: ${JSON.stringify(e)}`);
}
);
autoUpdater.on('update-downloaded', (info) => {

// For debugging
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: `AutoUpdater: Update downloaded ` + info }
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{
content: `updates: ${updates?.updateInfo.version} ${updates?.updateInfo.releaseName}`,
}
);
sendStatusToWindow('Update downloaded');
autoUpdater.quitAndInstall(undefined, true);
});

mainWindow!.loadURL(resolveHtmlPath('index.html'));

mainWindow!.on('ready-to-show', () => {
if (updateAvailable) {
win.on('ready-to-show', () => {
if (!win) {
if (updates?.updateInfo.version !== currentAppVersion) {
updateWindow.on('ready-to-show', () => {
if (!updateWindow) {
throw new Error('subwindow not defined');
}
win.show();
updateWindow.show();
});
}

// There should be a prompt asking if the user wants to update if ever the update is optional
if (autoUpdater.autoDownload) {
autoUpdater.downloadUpdate();
}

autoUpdater.on('update-available', (info: unknown) => {
axios.post(
'https://discord.com/api/webhooks/906911530820436010/Qh-u35ioUerJ925NnBkWTZ6l4RY1-M7sei7_EXxt_6l-nkRXmuxVNpHEC-P3hyzZji2m',
{ content: `Manual update ongoing` }
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{ content: `AutoUpdater: Update available. ${info}` }
);
sendStatusToWindow('Update available.');
autoUpdater.downloadUpdate();
updateAvailable = false;
}

// For debugging
axios.post(
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{ content: `Manual update ongoing` }
);
});

// AutoUpdater Listeners
autoUpdater.on('error', (err: string) => {
axios.post(
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{ content: `AutoUpdater: Error in auto-updater:${err}` }
);
sendStatusToWindow(`Error in auto-updater.:${err}`);
});
autoUpdater.on('update-not-available', (info: unknown) => {
axios.post(
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{ content: `Update not available: ${info}` }
);
sendStatusToWindow('Update not available.');
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.show();
}
});
autoUpdater.on(
'download-progress',
(progressObj: {
bytesPerSecond: string;
percent: string;
transferred: string;
total: string;
}) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
let log_message = `Download speed: ${progressObj.bytesPerSecond}`;
axios.post(
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{ content: `${log_message} - Downloaded ${progressObj.percent}%` }
);
log_message = `${log_message} - Downloaded ${progressObj.percent}%`;
log_message = `${log_message} (${progressObj.transferred}/${progressObj.total})`;
sendStatusToWindow(log_message);
}
);
autoUpdater.on('update-downloaded', (info) => {
axios.post(
'https://discord.com/api/webhooks/933196539201998988/J3ISuEbkKqXUaE8aP9IX8WhkPAQB48bwgkgN_Hy-CXH1jlEkTOypwpjm8sfALpOD1i8I',
{ content: `AutoUpdater: Update downloaded:${info}` }
);
sendStatusToWindow('Update downloaded');
autoUpdater.quitAndInstall(undefined, true);

if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.show();
}
});

if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
Expand All @@ -185,22 +262,19 @@ const createWindow = async () => {
}
});

mainWindow!.on('closed', () => {
mainWindow?.on('closed', () => {
controller.abort();
mainWindow = null;
});

const menuBuilder = new MenuBuilder(mainWindow!);
const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu();

// Open urls in the user's browser
mainWindow!.webContents.on('new-window', (event, url) => {
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});

// Remove this if your app does not use auto updates
// eslint-disable-next-line
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/screens/public/Login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Login = ({ loginUpdate, listProgrammingLanguagesSuccess }) => {
<img alt="CodeChum Logo" src={Logo} />
</div>
<Text className={styles.Login_text} type={textTypes.HEADING.MD}>
Welcome! Update 11
Welcome! Update 0.4.2
</Text>
<Formik
initialValues={{ login: '', password: '', overall: null }}
Expand Down
Loading

0 comments on commit 12be06f

Please sign in to comment.