Skip to content

Commit 812bdc8

Browse files
committed
feat: improve launch failure handling (closes #76)
1 parent 4b79aec commit 812bdc8

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src-tauri/src/database/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,26 @@ pub fn start_database(
4141

4242
thread::spawn(move || {
4343
let reader = BufReader::new(output);
44+
let mut has_started = false;
4445

4546
for line in reader.lines() {
4647
let message = line.unwrap();
4748

4849
println!("Surreal: {}", message);
4950

5051
window.emit("database:output", message).expect("console output should be delivered");
52+
53+
has_started = true;
5154
}
5255

5356
let elapsed = start_at.elapsed().as_millis();
5457

5558
if elapsed <= 500 {
56-
window.emit("database:error", "Surreal executable not found. Make sure the SurrealDB CLI is available in the command line.").expect("error result should be delivered");
59+
if !has_started {
60+
window.emit("database:output", "SurrealDB did not start. Are you sure the Surreal executable is available?").expect("console output should be delivered");
61+
}
62+
63+
window.emit("database:error", "SurrealDB did not start correctly, check the console for more information").expect("error result should be delivered");
5764
} else {
5865
window.emit("database:stop", true).expect("stop result should be delivered");
5966
}

src/components/ConsolePane/index.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useRef, useMemo } from "react";
22
import { Panel } from "~/components/Panel";
33
import { mdiClose, mdiConsole, mdiDelete } from "@mdi/js";
4-
import { ActionIcon, Group, ScrollArea, Text, useMantineTheme } from "@mantine/core";
4+
import { ActionIcon, Center, Group, ScrollArea, Text, useMantineTheme } from "@mantine/core";
55
import { Icon } from "~/components/Icon";
66
import { actions, store, useStoreValue } from "~/store";
77
import AnsiToHtml from "ansi-to-html";
@@ -82,6 +82,13 @@ export function ConsolePane() {
8282
icon={mdiConsole}
8383
rightSection={<ConsoleActions />}
8484
>
85+
{messages.length === 0 && (
86+
<Center h="100%">
87+
<Text c="light.5">
88+
No messages to display
89+
</Text>
90+
</Center>
91+
)}
8592
<ScrollArea
8693
style={{ position: 'absolute', inset: 12, top: 0 }}
8794
viewportRef={scroller}

src/components/Scaffold/index.tsx

+6-9
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export function Scaffold() {
4545
const activeTab = useStoreValue(state => state.config.activeTab);
4646
const environments = useStoreValue(state => state.config.environments);
4747
const autoConnect = useStoreValue(state => state.config.autoConnect);
48-
const servePending = useStoreValue(state => state.servePending);
49-
const isServing = useStoreValue(state => state.isServing);
5048
const enableConsole = useStoreValue(state => state.config.enableConsole);
5149
const isConnected = useStoreValue(state => state.isConnected);
5250
const tabInfo = useActiveTab();
@@ -168,7 +166,7 @@ export function Scaffold() {
168166

169167
const revealConsole = useStable((e: MouseEvent) => {
170168
e.stopPropagation();
171-
store.dispatch(actions.setConsoleEnabled(true));
169+
store.dispatch(actions.setConsoleEnabled(!enableConsole));
172170
});
173171

174172
const openTabCreator = useStable((envId?: string) => {
@@ -205,7 +203,6 @@ export function Scaffold() {
205203
const mergedInfoDetails = mergeConnections(tabInfo?.connection || {}, envInfo?.connection || {});
206204
const detailsValid = isConnectionValid(mergedInfoDetails);
207205

208-
const showConsole = enableConsole && (servePending || isServing);
209206
const borderColor = theme.fn.themeColor(isConnected ? 'surreal' : (detailsValid ? 'light' : 'red'));
210207
const viewMode = tabInfo?.activeView || 'query';
211208
const viewInfo = VIEW_MODES.find(v => v.id == viewMode)!;
@@ -401,14 +398,14 @@ export function Scaffold() {
401398
Connection details incomplete
402399
</Text>
403400
)}
404-
{(servePending || isServing) && !showConsole && (
401+
{/* {(servePending || isServing) && !showConsole && ( */}
405402
<ActionIcon
406403
onClick={revealConsole}
407-
title="Reveal console"
404+
title="Toggle console"
408405
>
409406
<Icon color="light.4" path={mdiConsole} />
410407
</ActionIcon>
411-
)}
408+
{/* )} */}
412409
{isConnected && (
413410
<ActionIcon
414411
onClick={closeConnection}
@@ -448,7 +445,7 @@ export function Scaffold() {
448445
minSize={100}
449446
bufferSize={200}
450447
direction="vertical"
451-
endPane={showConsole && (
448+
endPane={enableConsole && (
452449
<ConsolePane />
453450
)}
454451
>
@@ -497,7 +494,7 @@ export function Scaffold() {
497494
</Text>
498495
<Center mt="lg">
499496
<Button size="xs" onClick={createNewTab}>
500-
Create tab
497+
Create session
501498
</Button>
502499
</Center>
503500
</div>

src/store.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const mainSlice = createSlice({
160160

161161
prepareServe(state) {
162162
state.servePending = true;
163+
state.consoleOutput = [];
163164
},
164165

165166
confirmServing(state) {
@@ -170,7 +171,6 @@ const mainSlice = createSlice({
170171
stopServing(state) {
171172
state.isServing = false;
172173
state.servePending = false;
173-
state.consoleOutput = [];
174174
},
175175

176176
cancelServe(state) {

0 commit comments

Comments
 (0)