refactor and restructure

This commit is contained in:
Rushikesh Tote 2022-03-07 16:04:54 +05:30
parent bccaf54f17
commit 9a48ee096b
No known key found for this signature in database
GPG key ID: E4461ACF821B1DA8
13 changed files with 27 additions and 20 deletions

3
.gitmodules vendored
View file

@ -0,0 +1,3 @@
[submodule "src/renderer"]
path = src/renderer
url = https://github.com/ente-io/bada-frame

View file

@ -4,7 +4,7 @@
"version": "1.3.3",
"private": true,
"description": "Desktop client for ente.io",
"main": "app/main.js",
"main": "app/main/main.js",
"build": {
"appId": "io.ente.bhari-frame",
"artifactName": "${productName}-${version}.${ext}",
@ -35,12 +35,12 @@
},
"scripts": {
"postinstall": "electron-builder install-app-deps",
"build": "tsc",
"build-main": "tsc",
"watch": "tsc -w",
"lint": "eslint -c .eslintrc --ext .ts ./src",
"start": "concurrently \"yarn build && electron ./app/main.js\" \"cd bada-frame && yarn dev\"",
"build-source" : "cd bada-frame && yarn && yarn build && cd ..",
"test-release": "yarn && yarn build-source && yarn build && electron-builder",
"start": "concurrently \"yarn && yarn run build-main && electron ./app/main/main.js\" \"cd src/renderer && yarn && yarn dev\"",
"build-renderer" : "cd src/renderer && yarn && yarn build && cd ../../",
"test-release": "yarn && yarn build-renderer && yarn run build-main && electron-builder",
"release": "electron-builder -mwl --publish always"
},
"author": "ente <code@ente.io>",

4
src/config.ts Normal file
View file

@ -0,0 +1,4 @@
const PROD_HOST_URL: string = 'next://app';
const RENDERER_OUTPUT_DIR: string = './src/renderer/out';
export { PROD_HOST_URL, RENDERER_OUTPUT_DIR };

View file

@ -6,8 +6,7 @@ import { createWindow } from './utils/createWindow';
import setupIpcComs from './utils/ipcComms';
import { buildContextMenu, buildMenuBar } from './utils/menuUtil';
import initSentry from './utils/sentry';
const HOST_URL: string = 'next://app';
import { PROD_HOST_URL, RENDERER_OUTPUT_DIR } from '../config';
let tray: Tray;
let mainWindow: BrowserWindow;
@ -31,8 +30,8 @@ export const setIsUpdateAvailable = (value: boolean): void => {
};
const serveNextAt = require('next-electron-server');
serveNextAt(HOST_URL, {
outputDir: './bada-frame/out',
serveNextAt(PROD_HOST_URL, {
outputDir: RENDERER_OUTPUT_DIR,
});
// Disable error dialogs by overriding
@ -62,14 +61,14 @@ if (!gotTheLock) {
app.on('ready', () => {
initSentry();
setIsUpdateAvailable(false);
mainWindow = createWindow(HOST_URL);
mainWindow = createWindow();
Menu.setApplicationMenu(buildMenuBar());
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0)
createWindow(HOST_URL);
createWindow();
});
const trayImgPath = isDev
@ -80,7 +79,7 @@ if (!gotTheLock) {
tray.setToolTip('ente');
tray.setContextMenu(buildContextMenu(mainWindow));
setupIpcComs(tray, mainWindow, HOST_URL);
setupIpcComs(tray, mainWindow);
if (!isDev) {
AppUpdater.checkForUpdate(tray, mainWindow);
}

View file

@ -3,8 +3,9 @@ import * as isDev from 'electron-is-dev';
import * as path from 'path';
import { isAppQuitting } from '../main';
import { addAllowOriginHeader } from './cors';
import { PROD_HOST_URL } from '../../config';
export function createWindow(HOST_URL: string): BrowserWindow {
export function createWindow(): BrowserWindow {
const appImgPath = isDev
? 'build/window-icon.png'
: path.join(process.resourcesPath, 'window-icon.png');
@ -34,14 +35,14 @@ export function createWindow(HOST_URL: string): BrowserWindow {
if (isDev) {
splash.loadFile(`../build/splash.html`);
mainWindow.loadURL(HOST_URL);
mainWindow.loadURL(PROD_HOST_URL);
// Open the DevTools.
mainWindow.webContents.openDevTools();
} else {
splash.loadURL(
`file://${path.join(process.resourcesPath, 'splash.html')}`
);
mainWindow.loadURL(HOST_URL);
mainWindow.loadURL(PROD_HOST_URL);
}
mainWindow.webContents.on('did-fail-load', () => {
splash.close();

View file

@ -4,8 +4,7 @@ import { buildContextMenu } from './menuUtil';
export default function setupIpcComs(
tray: Tray,
mainWindow: BrowserWindow,
HOST_URL: string
mainWindow: BrowserWindow
): void {
ipcMain.on('select-dir', async (event) => {
const dialogWindow = new BrowserWindow({
@ -40,7 +39,7 @@ export default function setupIpcComs(
new Notification(notification).show();
});
ipcMain.on('reload-window', (event, args) => {
const secondWindow = createWindow(HOST_URL);
const secondWindow = createWindow();
mainWindow.destroy();
mainWindow = secondWindow;
});

View file

@ -5,7 +5,7 @@ import * as isDev from 'electron-is-dev';
const SENTRY_DSN = 'https://e9268b784d1042a7a116f53c58ad2165@sentry.ente.io/5';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const version = require('../../package.json').version;
const version = require('../../../package.json').version;
function initSentry(): void {
Sentry.init({

1
src/renderer Submodule

@ -0,0 +1 @@
Subproject commit 5b82ce85a2b2b1e15280806711d6c8e22daf6762

View file

@ -9,5 +9,5 @@
"*": ["node_modules/*"]
}
},
"include": ["src/**/*"]
"include": ["src/main/**/*"]
}