Skip to content

Commit 8aab6d3

Browse files
authored
Merge pull request #242 from x1unix/chore/release-v1.13.1
Release v1.13.1
2 parents 189f584 + 8b43ce7 commit 8aab6d3

File tree

15 files changed

+288
-47
lines changed

15 files changed

+288
-47
lines changed

build.mk

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,31 @@ PUBLIC_DIR ?= $(UI)/public
66
WEBWORKER_PKG ?= ./cmd/webworker
77
INTERPRETER_PKG ?= ./cmd/go-repl
88

9+
define build_wasm_worker
10+
@echo ":: Building WebAssembly worker '$(1)' ..."
11+
GOOS=js GOARCH=wasm $(GO) build -ldflags "-s -w" -trimpath \
12+
$(3) -o $(PUBLIC_DIR)/$(2) $(1)
13+
endef
14+
15+
define check_tool
16+
@if ! command -v $(1) >/dev/null 2>&1 ; then\
17+
echo "ERROR: '$(1)' binary not found. Please ensure that tool is installed or specify binary path with '$(2)' variable." && \
18+
exit 1; \
19+
fi;
20+
endef
21+
22+
923
.PHONY: clean
1024
clean:
1125
@echo ":: Cleanup..." && rm -rf $(TARGET) && rm -rf $(UI)/build
1226

1327
.PHONY:check-go
1428
check-go:
15-
@if ! command -v $(GO) >/dev/null 2>&1 ; then\
16-
echo "ERROR: '$(GO)' binary not found. Please ensure that Go is installed or specify binary path with 'GO' variable." && \
17-
exit 1; \
18-
fi;
29+
$(call check_tool,$(GO),'GO')
1930

2031
.PHONY:check-yarn
2132
check-yarn:
22-
@if ! command -v $(YARN) >/dev/null 2>&1 ; then\
23-
echo "ERROR: '$(YARN)' binary not found. Please ensure that Node.js and Yarn are installed or specify binary path with 'YARN' variable." && \
24-
exit 1; \
25-
fi;
33+
$(call check_tool,$(YARN),'YARN')
2634

2735
# Build targets
2836
.PHONY: collect-meta
@@ -51,13 +59,11 @@ copy-wasm-exec:
5159

5260
.PHONY:build-webworker
5361
build-webworker:
54-
@echo ":: Building Go Webworker module..." && \
55-
GOOS=js GOARCH=wasm $(GO) build -o $(PUBLIC_DIR)/worker.wasm $(WEBWORKER_PKG)
62+
$(call build_wasm_worker,$(WEBWORKER_PKG),'worker.wasm')
5663

5764
.PHONY:go-repl
5865
go-repl:
59-
@echo ":: Building Go interpreter module..." && \
60-
GOOS=js GOARCH=wasm $(GO) build -o $(PUBLIC_DIR)/go-repl.wasm $(INTERPRETER_PKG)
66+
$(call build_wasm_worker,$(INTERPRETER_PKG),'go-repl.wasm')
6167

6268
.PHONY:build-wasm
6369
build-wasm: copy-wasm-exec build-webworker go-repl

build/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ COPY go.sum .
2121
ARG APP_VERSION=1.0.0
2222
RUN echo "Building server with version $APP_VERSION" && \
2323
go build -o server -ldflags="-X 'main.Version=$APP_VERSION'" ./cmd/playground && \
24-
GOOS=js GOARCH=wasm go build -o ./go-repl.wasm ./cmd/go-repl && \
25-
GOOS=js GOARCH=wasm go build -o ./worker.wasm ./cmd/webworker && \
24+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./go-repl.wasm ./cmd/go-repl && \
25+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./worker.wasm ./cmd/webworker && \
2626
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
2727

2828
FROM golang:1.19-alpine as production

build/release.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ COPY go.sum .
1717
ARG APP_VERSION=1.0.0
1818
RUN echo "Building server with version $APP_VERSION" && \
1919
go build -o server -ldflags="-X 'main.Version=$APP_VERSION'" ./cmd/playground && \
20-
GOOS=js GOARCH=wasm go build -o ./worker.wasm ./cmd/webworker && \
21-
GOOS=js GOARCH=wasm go build -o ./go-repl.wasm ./cmd/go-repl && \
20+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./worker.wasm ./cmd/webworker && \
21+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./go-repl.wasm ./cmd/go-repl && \
2222
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
2323

2424
FROM golang:1.19-alpine as production

web/src/components/modals/Notification/Notification.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232
margin-bottom: .4rem;
3333
}
3434

35+
.Notification__Actions {
36+
margin-top: 1rem;
37+
}

web/src/components/modals/Notification/Notification.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import React from "react";
2-
import {IconButton, ISemanticColors, ProgressIndicator, useTheme} from "@fluentui/react";
2+
import {
3+
Stack,
4+
IconButton,
5+
ISemanticColors,
6+
ProgressIndicator,
7+
DefaultButton,
8+
PrimaryButton,
9+
useTheme,
10+
} from "@fluentui/react";
311
import { FontIcon } from "@fluentui/react/lib/Icon";
412

513
import "./Notification.css"
@@ -17,6 +25,13 @@ interface ProgressState {
1725
current?: number
1826
}
1927

28+
interface NotificationAction {
29+
label: string
30+
key: string
31+
primary?: boolean
32+
onClick?: () => void
33+
}
34+
2035
export interface NotificationProps {
2136
id: number|string
2237
type?: NotificationType
@@ -25,6 +40,7 @@ export interface NotificationProps {
2540
canDismiss?: boolean
2641
progress?: ProgressState
2742
onClose?: () => void
43+
actions?: NotificationAction[]
2844
}
2945

3046
const iconColorPaletteMap: {[k in NotificationType]: keyof ISemanticColors} = {
@@ -51,6 +67,19 @@ const getPercentComplete = (progress: NotificationProps['progress']): (number|un
5167
return percentage / 100;
5268
}
5369

70+
const NotificationActionButton: React.FC<Omit<NotificationAction, 'key'>> = (
71+
{label, primary, onClick}
72+
) => {
73+
const ButtonComponent = primary ? PrimaryButton : DefaultButton;
74+
return (
75+
<ButtonComponent
76+
primary={primary}
77+
onClick={onClick}
78+
text={label}
79+
/>
80+
);
81+
}
82+
5483
const Notification: React.FunctionComponent<NotificationProps> = ({
5584
id,
5685
title,
@@ -59,6 +88,7 @@ const Notification: React.FunctionComponent<NotificationProps> = ({
5988
canDismiss = true,
6089
type = NotificationType.Info,
6190
onClose,
91+
actions
6292
}) => {
6393
const {semanticColors, fonts, ...theme} = useTheme();
6494
return (
@@ -121,6 +151,22 @@ const Notification: React.FunctionComponent<NotificationProps> = ({
121151
)}
122152
</div>
123153
)}
154+
{ actions?.length && (
155+
<Stack
156+
horizontal
157+
className="Notification__Actions"
158+
horizontalAlign="end"
159+
tokens={
160+
{ childrenGap: 10 }
161+
}
162+
>
163+
{
164+
actions.map(({key, ...props}, i) => (
165+
<NotificationActionButton key={key} {...props} />
166+
))
167+
}
168+
</Stack>
169+
)}
124170

125171
</div>
126172
);

web/src/components/pages/Playground.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import React from 'react';
1+
import React, {useEffect} from 'react';
22
import { useParams } from 'react-router-dom';
33
import { connect } from 'react-redux';
44

5-
import { dispatchPanelLayoutChange, newSnippetLoadDispatcher} from '~/store';
5+
import {
6+
dispatchPanelLayoutChange,
7+
dispatchUpdateCheck,
8+
newSnippetLoadDispatcher,
9+
} from '~/store';
610
import { Header } from '~/components/core/Header';
711
import CodeEditor from '~/components/editor/CodeEditor';
812
import FlexContainer from '~/components/editor/FlexContainer';
@@ -15,7 +19,13 @@ import './Playground.css';
1519

1620
const CodeContainer = connect()(({dispatch}: any) => {
1721
const { snippetID } = useParams();
18-
dispatch(newSnippetLoadDispatcher(snippetID));
22+
useEffect(() => {
23+
dispatch(newSnippetLoadDispatcher(snippetID));
24+
}, [snippetID, dispatch]);
25+
26+
useEffect(() => {
27+
dispatch(dispatchUpdateCheck)
28+
}, [dispatch]);
1929
return (
2030
<CodeEditor />
2131
);
@@ -31,7 +41,9 @@ const Playground = connect(({panel}: any) => ({panelProps: panel}))(({panelProps
3141
</FlexContainer>
3242
<ResizablePreview
3343
{...panelProps}
34-
onViewChange={changes => dispatch(dispatchPanelLayoutChange(changes))}
44+
onViewChange={changes => {
45+
dispatch(dispatchPanelLayoutChange(changes))
46+
}}
3547
/>
3648
<NotificationHost />
3749
</Layout>

web/src/serviceWorkerRegistration.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ export function register(config?: Config) {
6161
}
6262
}
6363

64+
/**
65+
* Manually registers service worker
66+
*
67+
* @param config
68+
*/
69+
export function manualRegister(config?: Config) {
70+
if (process.env.NODE_ENV !== 'production') {
71+
return;
72+
}
73+
if (!('serviceWorker' in navigator)) {
74+
return;
75+
}
76+
77+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
78+
if (publicUrl.origin !== window.location.origin) {
79+
return;
80+
}
81+
82+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
83+
if (isLocalhost) {
84+
checkValidServiceWorker(swUrl, config);
85+
return;
86+
}
87+
88+
registerValidSW(swUrl, config);
89+
}
90+
6491
function registerValidSW(swUrl: string, config?: Config) {
6592
navigator.serviceWorker
6693
.register(swUrl)

web/src/services/updates.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import client from '~/services/api';
2+
import environment from "~/environment";
3+
4+
export interface UpdateInfo {
5+
newVersion: string
6+
}
7+
8+
/**
9+
* Checks for application updates and returns new available version.
10+
*
11+
* Returns null if no updates available.
12+
*/
13+
export const checkUpdates = async (): Promise<UpdateInfo|null> => {
14+
if (!window.navigator.onLine) {
15+
console.log('updater: application is offline, skip.');
16+
return null;
17+
}
18+
19+
const { version: newVersion } = await client.getVersion();
20+
const { appVersion } = environment;
21+
if (newVersion === appVersion) {
22+
console.log('updater: app is up to date:', newVersion);
23+
return null;
24+
}
25+
26+
console.log(`updater: new update is available - ${newVersion}`);
27+
return {
28+
newVersion: newVersion
29+
}
30+
31+
// if (!('serviceWorker' in navigator)) {
32+
// console.warn('updater: no SW registrations found, skip');
33+
// return;
34+
// }
35+
//
36+
// const registrations = await navigator.serviceWorker.getRegistrations();
37+
// if (!registrations?.length) {
38+
// console.warn('updater: no SW registrations found, skip');
39+
// return;
40+
// }
41+
42+
43+
// await truncateCachesAndRegister(registrations);
44+
}
45+
46+
// const truncateCachesAndRegister = async (registrations: readonly ServiceWorkerRegistration[]) => {
47+
// console.log(`updater: unregistering ${registrations.length} service workers...`);
48+
// await Promise.all(registrations.map(r => r.unregister()));
49+
//
50+
// console.log('updater: truncating caches', caches.keys());
51+
//
52+
// for (const sw of registrations) {
53+
// const ok = await sw.unregister();
54+
// if (!ok) {
55+
// console.
56+
// }
57+
// }
58+
// console.log('updater: truncating all caches');
59+
// }

web/src/store/actions/actions.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
export enum ActionType {
2-
IMPORT_FILE = 'IMPORT_FILE',
3-
FILE_CHANGE = 'FILE_CHANGE',
4-
LOADING = 'LOADING',
5-
ERROR = 'ERROR',
6-
FORMAT_CODE = 'FORMAT_CODE',
7-
TOGGLE_THEME = 'TOGGLE_THEME',
8-
RUN_TARGET_CHANGE = 'RUN_TARGET_CHANGE',
9-
MONACO_SETTINGS_CHANGE = 'MONACO_SETTINGS_CHANGE',
10-
UI_STATE_CHANGE = 'UI_STATE_CHANGE',
11-
MARKER_CHANGE = 'MARKER_CHANGE',
12-
PANEL_STATE_CHANGE = 'PANEL_STATE_CHANGE',
13-
SETTINGS_CHANGE = 'SETTINGS_CHANGE',
2+
IMPORT_FILE = 'IMPORT_FILE',
3+
FILE_CHANGE = 'FILE_CHANGE',
4+
LOADING_STATE_CHANGE = 'LOADING_STATE_CHANGE',
5+
ERROR = 'ERROR',
6+
FORMAT_CODE = 'FORMAT_CODE',
7+
TOGGLE_THEME = 'TOGGLE_THEME',
8+
RUN_TARGET_CHANGE = 'RUN_TARGET_CHANGE',
9+
MONACO_SETTINGS_CHANGE = 'MONACO_SETTINGS_CHANGE',
10+
UI_STATE_CHANGE = 'UI_STATE_CHANGE',
11+
MARKER_CHANGE = 'MARKER_CHANGE',
12+
PANEL_STATE_CHANGE = 'PANEL_STATE_CHANGE',
13+
SETTINGS_CHANGE = 'SETTINGS_CHANGE',
1414

1515
// Special actions used by Go WASM bridge
1616
EVAL_START = 'EVAL_START',

web/src/store/actions/ui.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { ActionType} from "./actions";
2-
32
import { UIState } from "../state";
43

4+
export interface LoadingStateChanges {
5+
loading: boolean
6+
}
7+
58
export const newUIStateChangeAction = (changes: Partial<UIState>) => (
69
{
710
type: ActionType.UI_STATE_CHANGE,
@@ -16,9 +19,9 @@ export const newErrorAction = (err: string) => (
1619
}
1720
);
1821

19-
export const newLoadingAction = () => (
22+
export const newLoadingAction = (loading = true) => (
2023
{
21-
type: ActionType.LOADING,
22-
payload: null,
24+
type: ActionType.LOADING_STATE_CHANGE,
25+
payload: { loading },
2326
}
2427
);

0 commit comments

Comments
 (0)