Skip to content

Commit

Permalink
Merge pull request #51 from 0916dhkim/welcome-screen-version
Browse files Browse the repository at this point in the history
Show Version Number On The Welcome Screen
  • Loading branch information
0916dhkim committed Mar 15, 2020
2 parents c65ba13 + 8261613 commit 1f21087
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bookery",
"version": "0.10.0-alpha",
"version": "0.10.1-alpha",
"description": "======= Bookery =======",
"main": "dist/main/main.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/common/request.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type RequestType =
| "GET-VERSION"
| "CLOSE-WINDOW"
| "SHOW-OPEN-DIALOG"
| "SHOW-SAVE-DIALOG"
Expand All @@ -7,6 +8,7 @@ export type RequestType =
| "SHOW-ERROR-MESSAGE";

export type RequestOptions<T extends RequestType> = { type: T } & {
"GET-VERSION": {};
"CLOSE-WINDOW": {};
"SHOW-OPEN-DIALOG": {};
"SHOW-SAVE-DIALOG": {};
Expand All @@ -26,6 +28,7 @@ export type WarningMessageOption = "OK" | "Cancel";
export type OverrideWarningOption = "Save" | "Don't Save" | "Cancel";

export type Response<T extends RequestType> = {
"GET-VERSION": string;
"CLOSE-WINDOW": void;
"SHOW-OPEN-DIALOG": string | null;
"SHOW-SAVE-DIALOG": string | null;
Expand Down
5 changes: 5 additions & 0 deletions src/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const isDevelopment = process.env.NODE_ENV !== "production";
let mainWindow: BrowserWindow | null = null;
let closeRequestReceived = false;

async function getVersionRequestHandler(): Promise<Response<"GET-VERSION">> {
return app.getVersion();
}

async function closeRequestHandler(): Promise<Response<"CLOSE-WINDOW">> {
closeRequestReceived = true;
mainWindow?.close();
Expand Down Expand Up @@ -152,6 +156,7 @@ function createMainWindow(): BrowserWindow {
});
});

registerRequestHandler("GET-VERSION", getVersionRequestHandler);
registerRequestHandler("CLOSE-WINDOW", closeRequestHandler);
registerRequestHandler("SHOW-OPEN-DIALOG", showOpenDialogRequestHandler);
registerRequestHandler("SHOW-SAVE-DIALOG", showSaveDialogRequestHandler);
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Request } from "../common/request";
import { RequestContext } from "./request_context";
import produce, { castDraft } from "immer";
import { UseEventHandler } from "../common/event";
import { WelcomeView } from "./welcome_view";

export interface RootProps {
request: Request;
Expand Down Expand Up @@ -305,7 +306,7 @@ export function Root({
saveFileMenuHandler.bind(null, request, dispatch, state)
);
if (!state.appData) {
return <p>Welcome Screen</p>;
return <WelcomeView request={request} />;
} else {
return (
<Container fluid>
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/welcome_view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from "react";
import { Request } from "../common/request";
import { Container } from "semantic-ui-react";

export interface WelcomeViewProps {
request: Request;
}

export function WelcomeView({
request
}: WelcomeViewProps): React.ReactElement<WelcomeViewProps> {
const [versionString, setVersionString] = React.useState<string>("");
Promise.resolve(request({ type: "GET-VERSION" })).then(setVersionString);
return (
<Container fluid>
<p>Welcome!</p>
<p>Version {versionString}</p>
</Container>
);
}

0 comments on commit 1f21087

Please sign in to comment.