Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
node_modules
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
"clsx": "2.1.1",
"esm-env": "1.2.2",
"svelte": "5.55.9"
},
"dependencies": {
}
}
23 changes: 13 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 76 additions & 58 deletions src/cod/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import prismIcon from '../assets/prism-launcher.svg';
import type { SpawnSession } from './spawn';
import TerminalWindow from './TerminalWindow.svelte';
import DropFile from '../vendor/DropFile.svelte';
import {
type TerminalLine,
type TerminalWindow as TerminalWindowModel,
Expand Down Expand Up @@ -1441,70 +1442,87 @@ PY`,
const sendTerminalInput = (id: string, input: string) => {
session?.input(id, input);
};
</script>

<div class="screen" {@attach attachVnc}></div>
const onDrop = async (files: File[]) => {
const transferFiles: Record<string,string> = {};
let script = '';
for(const file of files){
transferFiles[file.name + '._'] = btoa(String.fromCharCode(...new Uint8Array(await file.arrayBuffer())));
script = `${script};cat ${file.name}._ | base64 -d > ${file.name};rm ${file.name}._`
}
await session.transfer(transferFiles);
await startTaskTerminal({
id: `decode-files-${Date.now()}`,
title: 'Decode files',
command: script
})
}
</script>

{#if showRelativeMouseHint || relativeMouseEnabled}
<div class:active={relativeMouseEnabled} class="mouse-lock-hint">
{relativeMouseEnabled
? 'Relative mouse active. Press Esc to release.'
: 'Game detected. Ctrl+click the desktop for relative mouse.'}
</div>
{/if}

<TerminalWindow
{terminals}
open={terminalOpen}
activeTab={activeTerminalTab}
onClose={closeTerminalApp}
onSelectTab={selectTerminalTab}
onToggleTask={toggleTask}
onNewTerminal={launchTerminal}
onInput={sendTerminalInput}
/>

<div class:force-expand={loading} class="bar-anchor">
<nav class="bar" aria-label="Open windows">
{#each remoteWindows as window (window.id)}
<button
class="app-entry alive m3-layer"
type="button"
title={window.title}
onclick={() => focusRemoteWindow(window)}
>
<span>{window.title}</span>
</button>
{/each}
<button
class="app-entry m3-layer"
class:alive={terminalOpen || terminals.length > 0}
type="button"
title="Terminal"
onclick={() => openTerminalApp()}
>
<span>Terminal</span>
</button>
{#each launcherApps as app (app.id)}
{#if app.isInstalled() && !app.isRunning()}
<DropFile onDrop={onDrop}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a window-level event listener (<svelte:window>) instead so that we don't add a layer of indentation to everything and don't need another dep

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this run in another window, so <svelte:window> targets the wrong window?

https://svelte.dev/docs/svelte/svelte-window

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point. can add listeners in app.ts then

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up vendoring svelte-parts's DropFile, is that okay?

<div class="screen" {@attach attachVnc}></div>

{#if showRelativeMouseHint || relativeMouseEnabled}
<div class:active={relativeMouseEnabled} class="mouse-lock-hint">
{relativeMouseEnabled
? 'Relative mouse active. Press Esc to release.'
: 'Game detected. Ctrl+click the desktop for relative mouse.'}
</div>
{/if}

<TerminalWindow
{terminals}
open={terminalOpen}
activeTab={activeTerminalTab}
onClose={closeTerminalApp}
onSelectTab={selectTerminalTab}
onToggleTask={toggleTask}
onNewTerminal={launchTerminal}
onInput={sendTerminalInput}
/>

<div class:force-expand={loading} class="bar-anchor">
<nav class="bar" aria-label="Open windows">
{#each remoteWindows as window (window.id)}
<button
class="app-entry launcher m3-layer"
class="app-entry alive m3-layer"
type="button"
title={`Launch ${app.name}`}
aria-label={`Launch ${app.name}`}
onclick={app.launch}
title={window.title}
onclick={() => focusRemoteWindow(window)}
>
{@html app.icon}
<span>{app.name}</span>
<span>{window.title}</span>
</button>
{/if}
{/each}
</nav>
</div>

<div class:hidden={!loading} class="loader">
<img src={cod} alt="Loading Cod" />
</div>
{/each}
<button
class="app-entry m3-layer"
class:alive={terminalOpen || terminals.length > 0}
type="button"
title="Terminal"
onclick={() => openTerminalApp()}
>
<span>Terminal</span>
</button>
{#each launcherApps as app (app.id)}
{#if app.isInstalled() && !app.isRunning()}
<button
class="app-entry launcher m3-layer"
type="button"
title={`Launch ${app.name}`}
aria-label={`Launch ${app.name}`}
onclick={app.launch}
>
{@html app.icon}
<span>{app.name}</span>
</button>
{/if}
{/each}
</nav>
</div>

<div class:hidden={!loading} class="loader">
<img src={cod} alt="Loading Cod" />
</div>
</DropFile>

<style>
.screen {
Expand Down
82 changes: 82 additions & 0 deletions src/vendor/DropFile.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<script lang="ts">
const { children, multiple, disabled, onDrop, onEnter, onLeave } = $props();

let isOver: boolean = false;
let input: HTMLInputElement;

const handleEnter = () => {
isOver = true;
if (onEnter) {
onEnter();
}
};

const handleLeave = () => {
isOver = false;
if (onLeave) {
onLeave();
}
};

const handleDrop = (e: DragEvent) => {
e.preventDefault();

if (!e?.dataTransfer?.items || disabled) {
return;
}
const items = Array.from(e.dataTransfer.files);
onDrop(items);
isOver = false;
};

const handleDragOver = (e: Event) => {
e.preventDefault();
};

const handleChange = (e: Event) => {
e.preventDefault();
const files: FileList = <FileList>(<HTMLInputElement>e.target).files;
onDrop(Array.from(files));
};

const onClick = () => {
input.click();
};

const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Enter') {
input.click();
}
};
</script>

<div
id="zone"
ondrop={handleDrop}
ondragover={handleDragOver}
ondragenter={handleEnter}
ondragleave={handleLeave}
onclick={onClick}
onkeydown={onKeyDown}
tabIndex={0}
>
{@render children()}
</div>
<input
id="hidden-input"
type="file"
onchange={handleChange}
bind:this={input}
{multiple}
{disabled}
/>

<style>
#zone {
width: 100%;
height: 100%;
}
#hidden-input {
display: none;
}
</style>