Skip to content

Commit

Permalink
support dev env, minor window changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelvg committed Nov 27, 2024
1 parent c5a1ed3 commit 4ffef03
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 20 deletions.
Empty file added .config/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ dist-api/
dist-app/
node_modules/
*.log
.config/*
!.config/.gitkeep
3 changes: 3 additions & 0 deletions api/channel-play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ export async function playInWindow(channel: Channel): Promise<boolean> {
webPreferences: {
nodeIntegration: false,
},
autoHideMenuBar: true,
});

window.setMenu(null);

await window.loadURL(embedLink);

window.on('closed', () => {
Expand Down
2 changes: 1 addition & 1 deletion api/config-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SourcesEnum } from './enums';
import { config } from './settings-file';

const SETTINGS_FILE_PATH = path.join(
app.getPath('documents'),
process.env.NODE_ENV !== 'dev' ? app.getPath('documents') : './.config',
'KolpaqueClientElectron.json',
);

Expand Down
5 changes: 3 additions & 2 deletions api/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { app } from 'electron';
import * as util from 'util';
import { AxiosError } from 'axios';

const clientAppDataPath = app.getPath('userData');
const clientAppDataPath =
process.env.NODE_ENV !== 'dev' ? app.getPath('userData') : './.config';

export const appLogPath = path.join(clientAppDataPath, 'app.log');
export const crashLogPath = path.join(clientAppDataPath, 'crash.log');
Expand All @@ -19,7 +20,7 @@ ipcMain.handle('config_logs', () => logsUi.slice().reverse());
ipcMain.on('logs_open_folder', () => {
addLogs('info', 'logs_open_folder');

shell.showItemInFolder(appLogPath);
shell.openPath(path.resolve(clientAppDataPath));
});

export function addLogs(
Expand Down
30 changes: 19 additions & 11 deletions api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ import { addLogs, crashLogPath } from './logs';
import { init } from './client-init';
import { CLIENT_VERSION } from './globals';

const isDev = process.env.NODE_ENV === 'dev';

addLogs('info', 'is_dev', isDev, CLIENT_VERSION);
addLogs(
'info',
'is_dev',
process.env.NODE_ENV,
process.env.REACT_ENV,
CLIENT_VERSION,
);

let forceQuit = false;

Expand Down Expand Up @@ -82,14 +86,16 @@ export const main: { mainWindow: BrowserWindow | undefined } = {

app.setName('Kolpaque Client');

app.on('second-instance', () => {
main.mainWindow!.show();
});
if (process.env.NODE_ENV !== 'dev') {
app.on('second-instance', () => {
main.mainWindow!.show();
});

const lockStatus = app.requestSingleInstanceLock();
const lockStatus = app.requestSingleInstanceLock();

if (!lockStatus) {
app.quit();
if (!lockStatus) {
app.quit();
}
}

function createWindow(): void {
Expand All @@ -116,10 +122,12 @@ function createWindow(): void {

mainWindow.setMenu(null);

if (isDev) {
if (process.env.REACT_ENV === 'dev') {
mainWindow.loadURL('http://localhost:10000');

mainWindow.webContents.openDevTools();
mainWindow.webContents.openDevTools({
mode: 'detach',
});
} else {
mainWindow.loadURL(
url.format({
Expand Down
4 changes: 2 additions & 2 deletions api/sync-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { config } from './settings-file';
import { ISavedSettingsFile } from './config-class';

const SYNC_ID_FILE_PATH = path.join(
app.getPath('documents'),
process.env.NODE_ENV !== 'dev' ? app.getPath('documents') : './.config',
'KolpaqueClientElectron_sync_id',
);
const SYNC_ENCRYPTION_KEY_FILE_PATH = path.join(
app.getPath('documents'),
process.env.NODE_ENV !== 'dev' ? app.getPath('documents') : './.config',
'KolpaqueClientElectron_encryption_key',
);

Expand Down
5 changes: 4 additions & 1 deletion api/version-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ ipcMain.on('client_getInfo', async () => {

ipcMain.on(
'client_getVersion',
(event) => (event.returnValue = CLIENT_VERSION),
(event) =>
(event.returnValue = `${CLIENT_VERSION}${
process.env.NODE_ENV === 'dev' ? ' DEV' : ''
}`),
);

function sendInfo(update: string): void {
Expand Down
4 changes: 3 additions & 1 deletion app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ module.exports = {
],
},
plugins: [
new HtmlWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Webpack Dev Server',
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"build:api": "tsc --project api/tsconfig.json",
"build": "yarn run build:api && yarn workspace app run build && ts-node build.ts",
"release": "yarn ts-node release.ts",
"start:api": "yarn build:api && cross-env NODE_ENV=dev electron .",
"start:api": "yarn run build:api && cross-env NODE_ENV=dev REACT_ENV=dev electron .",
"start:dev": "concurrently --kill-others \"yarn run start:api\" \"yarn workspace app run start\"",
"start": "yarn run build:api && yarn workspace app run build && electron ."
"start": "yarn run build:api && yarn workspace app run build && cross-env NODE_ENV=dev electron ."
},
"author": "KLPQ",
"license": "CC0-1.0",
Expand Down

0 comments on commit 4ffef03

Please sign in to comment.