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
2 changes: 1 addition & 1 deletion src/lib/components/CodeInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { invoke } from '@tauri-apps/api/tauri';
import * as settings from '$lib/utils/settings';
import { Status, type Response } from '$lib/types/api';
import { copyIfEnabled } from '$lib/utils/copy';
import { copyIfEnabled } from '$lib/utils/clipboard';

let inputCode = '';
let output = '';
Expand Down
15 changes: 14 additions & 1 deletion src/lib/components/Urlnput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
import { invoke } from '@tauri-apps/api/tauri';
import * as settings from '$lib/utils/settings';
import { Status, type Response } from '$lib/types/api';
import { copyIfEnabled } from '$lib/utils/copy';
import { copyIfEnabled } from '$lib/utils/clipboard';
import { onMount } from 'svelte';

let inputUrl = '';
let output = '';
let code = '';

onMount(async () => {
if (await settings.get('pasteOnLoad')) {
console.debug('pasteOnLoad is enabled');
const clipboardData = await navigator.clipboard.readText();
console.debug('clipboard data:', clipboardData);
try {
new URL(clipboardData);
inputUrl = clipboardData;
} catch (e) {}
}
});

async function create() {
const endpoint = await settings.get<string>('endpoint');
const response: Response = await invoke('create_clip_cmd', {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/copy.ts → src/lib/utils/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const copyToClipboard = async (text: string) => {
navigator.clipboard.writeText(text);
}

export const readFromClipboard = async () => {
return await navigator.clipboard.readText();
}

export const copyIfEnabled = async (text: string) => {
if (await settings.get<boolean>('copyToClipboard')) {
await copyToClipboard(text);
Expand Down
19 changes: 18 additions & 1 deletion src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import { get, set } from '$lib/utils/settings';

let endpoint = 'interclip.app';
let copyToClipboard = true;
let copyToClipboard = false;
let pasteOnLoad = false;

let output = '';

const save = () => {
Expand All @@ -22,6 +24,7 @@
console.debug('Loading settings');
endpoint = (await get<string>('endpoint')) ?? 'interclip.app';
copyToClipboard = (await get<boolean>('copyToClipboard')) ?? true;
pasteOnLoad = (await get<boolean>('pasteOnLoad')) ?? true;
console.debug('Settings loaded', { endpoint, copyToClipboard });
})();

Expand Down Expand Up @@ -51,6 +54,20 @@
}}
/>
</label>
<label>
Paste from clipboard automatically:
<input
type="checkbox"
bind:checked={pasteOnLoad}
on:change={(e) => {
//@ts-ignore
if (e?.target instanceof HTMLInputElement) {
pasteOnLoad = e?.target.checked;
}
set('pasteOnLoad', pasteOnLoad);
}}
/>
</label>
{#if output}
<p>{output}</p>
{/if}
Expand Down