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
5 changes: 3 additions & 2 deletions src/components/DialogBox/ExportProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { ref } from 'vue'
import { useState } from '#/store/SimulatorStore/state'
import { useProjectStore } from '#/store/projectStore'
import { generateSaveData } from '#/simulator/src/data/save'
import { downloadFile } from '#/simulator/src/utils'
import { downloadFile, showMessageImmediate } from '#/simulator/src/utils'
import { escapeHtml } from '#/simulator/src/utils'

export function ExportProject() {
Expand Down Expand Up @@ -73,7 +73,8 @@ const exportAsFile = async () => {
false
)
fileName = `${fileName.replace(/[^a-z0-9]/gi, '_')}.cv`
downloadFile(fileName, circuitData)
const downloadDir = await downloadFile(fileName, circuitData)
showMessageImmediate(`"${fileName}" saved successfully to ${downloadDir}`)
SimulatorState.dialogBox.export_project_dialog = false
}
</script>
Expand Down
18 changes: 15 additions & 3 deletions src/simulator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export function showMessage(mes: string) {
useActions().showMessage(mes, "success");
}

// Variant that bypasses dedupe so repeated identical messages are always shown
export function showMessageImmediate(mes: string) {
prevShowMessage = undefined;
showMessage(mes);
}

export function distance(x1: number, y1: number, x2: number, y2: number) {
return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
}
Expand Down Expand Up @@ -116,7 +122,10 @@ export function gateGenerateVerilog(gate, invert = false) {
}

// Helper function to download text
export function downloadFile(filename: string, text: string | number | boolean | JSON) {
export async function downloadFile(
filename: string,
text: string | number | boolean | JSON,
): Promise<string> {
if (isTauri()) {
return downloadFileDesktop(filename, text);
} else {
Expand All @@ -125,7 +134,7 @@ export function downloadFile(filename: string, text: string | number | boolean |
}

// For Web Application
export function downloadFileWeb(filename: string, text: string | number | boolean) {
export function downloadFileWeb(filename: string, text: string | number | boolean): string {
const pom = document.createElement("a");
pom.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
pom.setAttribute("download", filename);
Expand All @@ -137,13 +146,15 @@ export function downloadFileWeb(filename: string, text: string | number | boolea
} else {
pom.click();
}

return "Downloads";
}

// For Desktop Application
export async function downloadFileDesktop(
filename: string,
text: string | number | boolean | JSON,
) {
): Promise<string> {
const downloadsDirectory = await downloadDir();
let path = filename;

Expand All @@ -152,6 +163,7 @@ export async function downloadFileDesktop(
}

await writeTextFile(path, text.toString());
return downloadsDirectory;
}

// Helper function to open a new tab
Expand Down
5 changes: 3 additions & 2 deletions v1/src/components/DialogBox/ExportProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { ref } from 'vue'
import { useState } from '#/store/SimulatorStore/state'
import { useProjectStore } from '#/store/projectStore'
import { generateSaveData } from '#/simulator/src/data/save'
import { downloadFile } from '#/simulator/src/utils'
import { downloadFile, showMessageImmediate } from '#/simulator/src/utils'
import { escapeHtml } from '#/simulator/src/utils'

export function ExportProject() {
Expand Down Expand Up @@ -73,7 +73,8 @@ const exportAsFile = async () => {
false
)
fileName = `${fileName.replace(/[^a-z0-9]/gi, '_')}.cv`
downloadFile(fileName, circuitData)
const downloadDir = await downloadFile(fileName, circuitData)
showMessageImmediate(`"${fileName}" saved successfully to ${downloadDir}`)
SimulatorState.dialogBox.export_project_dialog = false
}
</script>
Expand Down
18 changes: 15 additions & 3 deletions v1/src/simulator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
useActions().showMessage(mes, "success");
}

// Variant that bypasses dedupe so repeated identical messages are always shown
export function showMessageImmediate(mes: string) {
prevShowMessage = undefined;
showMessage(mes);
}

export function distance(x1: number, y1: number, x2: number, y2: number) {
return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
}
Expand Down Expand Up @@ -116,7 +122,10 @@
}

// Helper function to download text
export function downloadFile(filename: string, text: string | number | boolean | JSON) {
export async function downloadFile(
filename: string,
text: string | number | boolean | JSON,
): Promise<string> {
if (isTauri()) {
return downloadFileDesktop(filename, text);
} else {
Expand All @@ -125,7 +134,7 @@
}

// For Web Application
export function downloadFileWeb(filename: string, text: string | number | boolean) {
export function downloadFileWeb(filename: string, text: string | number | boolean): string {
const pom = document.createElement("a");
pom.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
pom.setAttribute("download", filename);
Expand All @@ -137,13 +146,15 @@
} else {
pom.click();
}

return "Downloads";
}

// For Desktop Application
export async function downloadFileDesktop(
filename: string,
text: string | number | boolean | JSON,
) {
): Promise<string> {
const downloadsDirectory = await downloadDir();
let path = filename;

Expand All @@ -152,6 +163,7 @@
}

await writeTextFile(path, text.toString());
return downloadsDirectory;
}

// Helper function to open a new tab
Expand All @@ -175,7 +187,7 @@

// Check if there is any content selected previously.
const selected =
(document.getSelection()?.rangeCount ?? 0 > 0) ? document.getSelection()?.getRangeAt(0) : false;

Check warning on line 190 in v1/src/simulator/src/utils.ts

View workflow job for this annotation

GitHub Actions / lint

oxc(const-comparisons)

This comparison will always evaluate to false

// iOS Safari blocks programmatic execCommand copying normally, without this hack.
// https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios
Expand Down Expand Up @@ -226,7 +238,7 @@
}

export function getImageDimensions(file: string) {
return new Promise(function (resolved, rejected) {

Check warning on line 241 in v1/src/simulator/src/utils.ts

View workflow job for this annotation

GitHub Actions / lint

eslint(no-unused-vars)

Parameter 'rejected' is declared but never used. Unused parameters should start with a '_'.
const i = new Image();
i.onload = function () {
resolved({ w: i.width, h: i.height });
Expand Down Expand Up @@ -275,7 +287,7 @@
});
$("#bcdInput").on("keyup", function () {
var input = $("#bcdInput").val();
var num = 0;

Check warning on line 290 in v1/src/simulator/src/utils.ts

View workflow job for this annotation

GitHub Actions / lint

eslint(no-unused-vars)

Variable 'num' is assigned a value but never used. Unused variables should start with a '_'.
while (input.length % 4 !== 0) {
input = "0" + input;
}
Expand Down
Loading