forked from mirror/ObjToSchematic
Disabled queueing actions for now, enabled file logs
This commit is contained in:
parent
ed2114c1be
commit
8fb1804571
@ -14,7 +14,7 @@ import { UI } from './ui/layout';
|
|||||||
import { UIMessageBuilder } from './ui/misc';
|
import { UIMessageBuilder } from './ui/misc';
|
||||||
import { ColourSpace, EAction } from './util';
|
import { ColourSpace, EAction } from './util';
|
||||||
import { ASSERT } from './util/error_util';
|
import { ASSERT } from './util/error_util';
|
||||||
import { Logger } from './util/log_util';
|
import { LOG_ERROR, Logger } from './util/log_util';
|
||||||
import { TWorkerJob, WorkerController } from './worker_controller';
|
import { TWorkerJob, WorkerController } from './worker_controller';
|
||||||
import { TFromWorkerMessage, TToWorkerMessage } from './worker_types';
|
import { TFromWorkerMessage, TToWorkerMessage } from './worker_types';
|
||||||
|
|
||||||
@ -46,17 +46,18 @@ export class AppContext {
|
|||||||
public do(action: EAction) {
|
public do(action: EAction) {
|
||||||
this._ui.cacheValues(action);
|
this._ui.cacheValues(action);
|
||||||
this._ui.disable(action);
|
this._ui.disable(action);
|
||||||
|
this._ui.disableAll();
|
||||||
|
|
||||||
const workerJob = this._getWorkerJob(action);
|
const workerJob = this._getWorkerJob(action);
|
||||||
if (workerJob === undefined) {
|
if (workerJob === undefined) {
|
||||||
this._ui.enable(action);
|
this._ui.enableTo(action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uiOutput = this._ui.getActionOutput(action);
|
const uiOutput = this._ui.getActionOutput(action);
|
||||||
|
|
||||||
const jobCallback = (payload: TFromWorkerMessage) => {
|
const jobCallback = (payload: TFromWorkerMessage) => {
|
||||||
this._ui.enable(action);
|
this._ui.enableTo(action);
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
case 'KnownError':
|
case 'KnownError':
|
||||||
case 'UnknownError': {
|
case 'UnknownError': {
|
||||||
@ -66,10 +67,11 @@ export class AppContext {
|
|||||||
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
||||||
'error',
|
'error',
|
||||||
);
|
);
|
||||||
|
LOG_ERROR(payload.error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
this._ui.enable(action + 1);
|
this._ui.enableTo(action + 1);
|
||||||
|
|
||||||
const { builder, style } = this._getActionMessageBuilder(action, payload.statusMessages);
|
const { builder, style } = this._getActionMessageBuilder(action, payload.statusMessages);
|
||||||
uiOutput.setMessage(builder, style as OutputStyle);
|
uiOutput.setMessage(builder, style as OutputStyle);
|
||||||
@ -171,6 +173,7 @@ export class AppContext {
|
|||||||
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
||||||
'error',
|
'error',
|
||||||
);
|
);
|
||||||
|
LOG_ERROR(payload.error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -244,6 +247,7 @@ export class AppContext {
|
|||||||
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
||||||
'error',
|
'error',
|
||||||
);
|
);
|
||||||
|
LOG_ERROR(payload.error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -315,6 +319,7 @@ export class AppContext {
|
|||||||
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
[payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'],
|
||||||
'error',
|
'error',
|
||||||
);
|
);
|
||||||
|
LOG_ERROR(payload.error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -35,5 +35,5 @@ export namespace AppConfig {
|
|||||||
export const MAXIMUM_IMAGE_MEM_ALLOC = 512;
|
export const MAXIMUM_IMAGE_MEM_ALLOC = 512;
|
||||||
|
|
||||||
/** Whether of not all logs should be saved to a file */
|
/** Whether of not all logs should be saved to a file */
|
||||||
export const LOG_TO_FILE = false;
|
export const LOG_TO_FILE = true;
|
||||||
}
|
}
|
||||||
|
@ -482,6 +482,12 @@ export class UI {
|
|||||||
return this._uiDull;
|
return this._uiDull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enableTo(action: EAction) {
|
||||||
|
for (let i = 0; i <= action; ++i) {
|
||||||
|
this.enable(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enable(action: EAction) {
|
public enable(action: EAction) {
|
||||||
if (action >= EAction.MAX) {
|
if (action >= EAction.MAX) {
|
||||||
return;
|
return;
|
||||||
|
@ -12,8 +12,8 @@ export const LOG = (...data: any[]) => {
|
|||||||
if (Logger.Get.isLOGEnabled()) {
|
if (Logger.Get.isLOGEnabled()) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(...data);
|
console.log(...data);
|
||||||
Logger.Get.logToFile(...data);
|
|
||||||
}
|
}
|
||||||
|
Logger.Get.logToFile(...data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,8 +23,8 @@ export const LOG_MAJOR = (...data: any[]) => {
|
|||||||
if (Logger.Get.isLOGMAJOREnabled()) {
|
if (Logger.Get.isLOGMAJOREnabled()) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(...data);
|
console.log(...data);
|
||||||
Logger.Get.logToFile(...data);
|
|
||||||
}
|
}
|
||||||
|
Logger.Get.logToFile(...data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,8 +34,8 @@ export const LOG_WARN = (...data: any[]) => {
|
|||||||
if (Logger.Get.isLOGWARNEnabled()) {
|
if (Logger.Get.isLOGWARNEnabled()) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.warn(...data);
|
console.warn(...data);
|
||||||
Logger.Get.logToFile(...data);
|
|
||||||
}
|
}
|
||||||
|
Logger.Get.logToFile(...data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
@ -55,7 +55,7 @@ export class Logger {
|
|||||||
private _enabledLOGMAJOR: boolean;
|
private _enabledLOGMAJOR: boolean;
|
||||||
private _enabledLOGWARN: boolean;
|
private _enabledLOGWARN: boolean;
|
||||||
|
|
||||||
private _logStream: fs.WriteStream;
|
private _logStream?: fs.WriteStream;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this._enabledLOG = false;
|
this._enabledLOG = false;
|
||||||
@ -63,13 +63,13 @@ export class Logger {
|
|||||||
this._enabledLOGWARN = false;
|
this._enabledLOGWARN = false;
|
||||||
|
|
||||||
FileUtil.mkdirSyncIfNotExist(AppPaths.Get.logs);
|
FileUtil.mkdirSyncIfNotExist(AppPaths.Get.logs);
|
||||||
this._logStream = fs.createWriteStream(PathUtil.join(AppPaths.Get.logs, `./${Date.now()}.log`));
|
if (AppConfig.LOG_TO_FILE) {
|
||||||
|
this._logStream = fs.createWriteStream(PathUtil.join(AppPaths.Get.logs, `./${Date.now()}.log`));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public logToFile(...data: any[]) {
|
public logToFile(...data: any[]) {
|
||||||
if (AppConfig.LOG_TO_FILE) {
|
this._logStream?.write(util.format(...data) + '\n');
|
||||||
this._logStream.write(util.format(...data) + '\n');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enableLOG() {
|
public enableLOG() {
|
||||||
|
Loading…
Reference in New Issue
Block a user