Skip to content

Commit

Permalink
fix: added :restart command and made :cmd error handling better
Browse files Browse the repository at this point in the history
resolves #103
  • Loading branch information
daretodave committed May 9, 2024
1 parent 940b5d2 commit 3c2ef2d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/main/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface BootstrapContext {
icon: string
errorModal: ErrorModal
}
export async function boostrap(context: BootstrapContext): Promise<void> {
export async function bootstrap(context: BootstrapContext): Promise<void> {
const { app, workspace } = context

await app.whenReady()
Expand Down
4 changes: 3 additions & 1 deletion src/main/framework/runtime-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Settings from './system-commands/settings'
import Edit from './system-commands/edit'
import Reset from './system-commands/reset'
import Commands from './system-commands/commands'
import Restart from './system-commands/restart'

const systemCommands: Array<{
command: string
Expand All @@ -35,7 +36,8 @@ const systemCommands: Array<{
Settings,
Edit,
Reset,
Commands
Commands,
Restart
]
export async function execute(context: ExecuteContext): Promise<void | boolean> {
const [cmd, ...args] = context.command.prompt.split(' ')
Expand Down
8 changes: 7 additions & 1 deletion src/main/framework/system-commands/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExecuteContext } from '../execute-context'
import { errorModal } from '../../index'

export default {
command: ':commands',
Expand All @@ -15,7 +16,12 @@ export default {
await context.edit(context.workspace.commands.commandFileLocation, async () => {
context.out('Saved command file!\n')

await context.workspace.commands.load(context.workspace.settings)
try {
await context.workspace.commands.load(context.workspace.settings)
} catch (e) {
console.log(e)
await errorModal.showError(e)
}

context.out('Commands reloaded\n')
})
Expand Down
11 changes: 11 additions & 0 deletions src/main/framework/system-commands/restart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { app } from 'electron'

async function restart(): Promise<void> {
app.relaunch()
app.exit()
}

export default {
command: ':restart',
task: restart
}
73 changes: 0 additions & 73 deletions src/main/index.test.ts

This file was deleted.

9 changes: 5 additions & 4 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Workspace } from './framework/workspace'

import { DEFAULT_SETTINGS, DEFAULT_WORKSPACE } from '../constants'
import { ErrorModal } from './window/windows/error-modal'
import { boostrap } from './bootstrap'
import { bootstrap } from './bootstrap'
import { join } from 'path'

const workspace = new Workspace(DEFAULT_WORKSPACE, DEFAULT_SETTINGS)
Expand Down Expand Up @@ -34,17 +34,18 @@ const platform = new PlatformWindow(
false
)

const errorModal = new ErrorModal(
export const errorModal = new ErrorModal(
icon,
{
width: 600,
height: 600
height: 600,
alwaysOnTop: true
},
'error',
false
)

boostrap({
bootstrap({
icon,
workspace,
windows: [runner, platform, errorModal],
Expand Down
5 changes: 4 additions & 1 deletion src/main/vendor/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export async function compile(
stats
.toJson()
.errors?.map((o) => o.message)
.reduce((errorText, errorEntry) => `${errorText}\n${errorEntry}`, '')
.reduce(
(errorText, errorEntry) => `${errorText}\n${errorEntry.split('TS').join('\nTS')}`,
''
)
)
} else {
resolve()
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/src/error-runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ export default function ErrorRuntimePage(): ReactElement {
)
}

const errorMessage: string = info
let errorMessage: string = info

errorMessage = errorMessage.split('[tsl]').join('\n').split('TS').join('\n -> TS')

return (
<div id="error-page">
<h1>Oops!</h1>
<h1>Woa!</h1>
<p>Sorry, an unexpected error has occurred.</p>
<button onClick={exit}>Exit</button>
<button onClick={workspace}>Workspace</button>
<hr />
<pre>{errorMessage}</pre>
<pre dangerouslySetInnerHTML={{ __html: errorMessage }}></pre>
</div>
)
}

0 comments on commit 3c2ef2d

Please sign in to comment.