Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'reconnect' setting and patch noVNC to fix issue after browser tab has been idle. #20

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm-12c6f55b-ls87 AS buildstage
# taken from https://github.com/linuxserver/docker-baseimage-kasmvnc/blob/debianbookworm/Dockerfile
# modified to apply 'novnc.patch' (fixing a disconnect/reconnect issue)
FROM node:12-buster AS wwwstage

ARG KASMWEB_RELEASE="5ba4695e6526a27b8e38ec8d55dc33b39143e68a"

RUN \
echo "**** build clientside ****" && \
mkdir /src && \
cd /src && \
wget https://github.com/kasmtech/noVNC/tarball/${KASMWEB_RELEASE} -O - \
| tar --strip-components=1 -xz

COPY ./patches/novnc.patch /src/
RUN \
export QT_QPA_PLATFORM=offscreen && \
export QT_QPA_FONTDIR=/usr/share/fonts && \
echo "apply novnc.patch" && \
cd /src && \
patch -p1 -i novnc.patch && \
npm install && \
npm run-script build

RUN \
echo "**** organize output ****" && \
mkdir /build-out && \
cd /src && \
rm -rf node_modules/ && \
cp -R ./* /build-out/ && \
cd /build-out && \
rm *.md && \
rm AUTHORS && \
cp index.html vnc.html && \
mkdir Downloads

FROM ghcr.io/linuxserver/baseimage-kasmvnc:debianbookworm-f7a8978f-ls89 AS buildstage

# these are specified in Makefile
ARG ARCH
Expand Down Expand Up @@ -107,6 +142,7 @@ RUN \
FROM scratch

COPY --from=buildstage / .
COPY --from=wwwstage /build-out /usr/local/share/kasmvnc/www

# since we start from scratch, we need these env variables from the base images
ENV \
Expand Down
43 changes: 42 additions & 1 deletion Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
FROM ghcr.io/linuxserver/baseimage-kasmvnc:arm64v8-debianbookworm-12c6f55b-ls87 AS buildstage
# taken from https://github.com/linuxserver/docker-baseimage-kasmvnc/blob/debianbookworm/Dockerfile.aarch64
# modified to apply 'novnc.patch' (fixing a disconnect/reconnect issue)
FROM node:12-buster AS wwwstage

ARG KASMWEB_RELEASE="5ba4695e6526a27b8e38ec8d55dc33b39143e68a"

RUN \
echo "**** install build deps ****" && \
apt-get update && \
apt-get install -y phantomjs

RUN \
echo "**** build clientside ****" && \
mkdir /src && \
cd /src && \
wget https://github.com/kasmtech/noVNC/tarball/${KASMWEB_RELEASE} -O - \
| tar --strip-components=1 -xz

COPY ./patches/novnc.patch /src/
RUN \
export QT_QPA_PLATFORM=offscreen && \
export QT_QPA_FONTDIR=/usr/share/fonts && \
echo "apply novnc.patch" && \
cd /src && \
patch -p1 -i novnc.patch && \
npm install && \
npm run-script build

RUN \
echo "**** organize output ****" && \
mkdir /build-out && \
cd /src && \
rm -rf node_modules/ && \
cp -R ./* /build-out/ && \
cd /build-out && \
rm *.md && \
rm AUTHORS && \
cp index.html vnc.html && \
mkdir Downloads

FROM ghcr.io/linuxserver/baseimage-kasmvnc:arm64v8-debianbookworm-f7a8978f-ls89 AS buildstage

# these are specified in Makefile
ARG ARCH
Expand Down Expand Up @@ -107,6 +147,7 @@ RUN \
FROM scratch

COPY --from=buildstage / .
COPY --from=wwwstage /build-out /usr/local/share/kasmvnc/www

# since we start from scratch, we need these env variables from the base images
ENV \
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PKG_VERSION := $(shell yq e ".version" manifest.yaml)
TS_FILES := $(shell find ./ -name \*.ts)
ROOT_FILES := $(shell find ./root)
ASSET_FILES := $(shell find ./assets/compat)
PATCH_FILES := $(shell find ./patches)

.DELETE_ON_ERROR:

Expand Down Expand Up @@ -43,7 +44,7 @@ clean:
scripts/embassy.js: $(TS_FILES)
deno bundle scripts/embassy.ts scripts/embassy.js

docker-images/aarch64.tar: manifest.yaml Dockerfile.aarch64 docker_entrypoint.sh $(ROOT_FILES)
docker-images/aarch64.tar: manifest.yaml Dockerfile.aarch64 docker_entrypoint.sh $(ROOT_FILES) $(PATCH_FILES)
ifeq ($(ARCH),x86_64)
else
mkdir -p docker-images
Expand All @@ -58,7 +59,7 @@ else
--platform=linux/arm64 -o type=docker,dest=docker-images/aarch64.tar -f Dockerfile.aarch64 .
endif

docker-images/x86_64.tar: manifest.yaml Dockerfile docker_entrypoint.sh $(ROOT_FILES)
docker-images/x86_64.tar: manifest.yaml Dockerfile docker_entrypoint.sh $(ROOT_FILES) $(PATCH_FILES)
ifeq ($(ARCH),aarch64)
else
mkdir -p docker-images
Expand Down
7 changes: 7 additions & 0 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ if [ $(yq e '.sparrow.managesettings' /root/data/start9/config.yaml) = "true" ];
esac
fi

# remove reference to non-existing file, see: https://github.com/linuxserver/kclient/issues/8
sed -i '/<script src="public\/js\/pcm-player\.js"><\/script>/d' /kclient/public/index.html

# add '&reconnect=' setting to kclient html
RECONNECT=$(yq e '.reconnect' /root/data/start9/config.yaml)
sed -i "s/\(index\.html?autoconnect=1\)/&\&reconnect=$RECONNECT/" /kclient/public/index.html

# setup a proxy on localhost, Sparrow will not use Tor for local addresses
# this means we can connect straight to bitcoind/electrs and use Tor for everything else (whirlpool)
/usr/bin/socat tcp-l:8332,fork,reuseaddr,su=nobody,bind=127.0.0.1 tcp:bitcoind.embassy:8332 &
Expand Down
5 changes: 3 additions & 2 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
id: sparrow-webtop
title: "Sparrow"
version: 2.0.0
version: 2.0.0.1
release-notes: |
* Update to Sparrow 2.0.0 - See [full changelog](https://github.com/sparrowwallet/sparrow/releases/tag/2.0.0)
* Add 'Automatically reconnect' option. Enable this to reconnect to the desktop when the connection is lost or the browser tab has been idle for too long.
* fix a minor issue when browser tab becomes idle (Cannot read properties of undefined (reading 'lastActiveAt'))
license: GPLv3
wrapper-repo: "https://github.com/remcoros/sparrow-webtop-startos"
upstream-repo: "https://github.com/sparrowwallet/sparrow"
Expand Down
54 changes: 54 additions & 0 deletions patches/novnc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/app/ui.js b/app/ui.js
index d973ffd..8d9515e 100644
--- a/app/ui.js
+++ b/app/ui.js
@@ -1628,15 +1628,17 @@ const UI = {
// UI.disconnect() won't be used in those cases.
UI.connected = false;

+ clearInterval(UI._sessionTimeoutInterval);
+
UI.rfb = undefined;

if (!e.detail.clean) {
UI.updateVisualState('disconnected');
if (wasConnected) {
UI.showStatus(_("Something went wrong, connection is closed"),
- 'error');
+ 'error', 0, true);
} else {
- UI.showStatus(_("Failed to connect to server"), 'error');
+ UI.showStatus(_("Failed to connect to server"), 'error', 0, true);
}
} else if (UI.getSetting('reconnect', false) === true && !UI.inhibitReconnect) {
UI.updateVisualState('reconnecting');
@@ -1646,7 +1648,7 @@ const UI = {
return;
} else {
UI.updateVisualState('disconnected');
- UI.showStatus(_("Disconnected"), 'normal');
+ UI.showStatus(_("Disconnected"), 'error', 0, true);
}

document.title = PAGE_TITLE;
diff --git a/vnc.html b/vnc.html
index e5b5177..565f273 100644
--- a/vnc.html
+++ b/vnc.html
@@ -478,13 +478,14 @@
</div>
</li>
<li><hr></li>
- <li>
+ <li class="noVNC_hidden">
<label class="switch">
<input id="noVNC_setting_reconnect" type="checkbox">
+ <span class="slider round"></span>
<span class="slider-label">Automatic Reconnect</span>
</label>
</li>
- <li>
+ <li class="noVNC_hidden">
<label for="noVNC_setting_reconnect_delay">Reconnect Delay (ms):</label>
<input id="noVNC_setting_reconnect_delay" type="number">
</li>
6 changes: 6 additions & 0 deletions scripts/procedures/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export const getConfig: T.ExpectedExports.getConfig = compat.getConfig({
"pattern-description": "Must not contain newline or quote characters.",
copyable: true,
},
reconnect: {
type: "boolean",
name: "Automatically reconnect",
description: "Automatically reconnect when the connection to the desktop is lost or the browser tab has been idle for too long.",
default: false,
},
sparrow: {
type: "object",
name: "Sparrow settings",
Expand Down
21 changes: 20 additions & 1 deletion scripts/procedures/migrations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import { compat, types as T } from "../deps.ts";

export const migration: T.ExpectedExports.migration = compat.migrations
.fromMapping({}, "2.0.0" );
.fromMapping({
"2.0.0.1": {
up: compat.migrations.updateConfig(
(config: any) => {
config["reconnect"] = false;
return config;
},
true,
{ version: "2.0.0.1", type: "up" },
),
down: compat.migrations.updateConfig(
(config: any) => {
delete config["reconnect"];
return config;
},
true,
{ version: "2.0.0.1", type: "down" },
),
},
}, "2.0.0.1");