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
30 changes: 18 additions & 12 deletions app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
startSendSession,
store,
updateAliasState,
setPinState,
} from "@/services/store";
import { getAgentInfoString } from "~/utils/userAgent";
import { protocolVersion } from "~/services/webrtc";
Expand All @@ -108,6 +109,20 @@ const { t } = useI18n();

const { open: openFileDialog, onChange } = useFileDialog();

const minDelayFinished = ref(false);

const webCryptoSupported = ref(true);

const targetId = ref("");

const promptAndSavePin = async (): Promise<string | null> => {
const pin = prompt(t("index.enterPin"));
if (pin !== null) {
setPinState(pin);
}
return pin;
};

onChange(async (files) => {
if (!files) return;

Expand All @@ -118,17 +133,10 @@ onChange(async (files) => {
await startSendSession({
files,
targetId: targetId.value,
onPin: async () => {
return prompt(t("index.enterPin"));
},
onPin: promptAndSavePin,
});
});

const minDelayFinished = ref(false);
const webCryptoSupported = ref(true);

const targetId = ref("");

const selectPeer = (id: string) => {
targetId.value = id;
openFileDialog();
Expand Down Expand Up @@ -160,7 +168,7 @@ const updateAlias = async () => {
const updatePIN = async () => {
const pin = prompt(t("index.enterPin"));
if (typeof pin === "string") {
store.pin = pin ? pin : null;
setPinState(pin ? pin : null);
}
};

Expand Down Expand Up @@ -198,9 +206,7 @@ onMounted(async () => {
await setupConnection({
url: runtimeConfig.public.signalingUrl,
info,
onPin: async () => {
return prompt(t("index.enterPin"));
},
onPin: promptAndSavePin,
});
});
</script>
Expand Down
17 changes: 15 additions & 2 deletions app/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const store = reactive({
key: null as CryptoKeyPair | null,

/// PIN code used before receiving or sending files
pin: null as string | null,

pin: sessionStorage.getItem("transfer_pin") ?? null,
// Signaling connection to the server
signaling: null as SignalingConnection | null,

Expand Down Expand Up @@ -130,6 +129,20 @@ async function connectionLoop(url: string) {
}
}
}
watch(
() => store.pin,
(newPin) => {
if (newPin) {
sessionStorage.setItem("transfer_pin", newPin);
} else {
sessionStorage.removeItem("transfer_pin");
}
},
{ immediate: false }
);
export function setPinState(pin: string | null) {
store.pin = (pin && pin.trim() !== "") ? pin : null;
}

export function updateAliasState(alias: string) {
store._proposingClient!.alias = alias;
Expand Down