Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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, showMessage } 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)
showMessage(`"${fileName}" saved successfully to ${downloadDir}`)
SimulatorState.dialogBox.export_project_dialog = false
}
</script>
Expand Down
12 changes: 9 additions & 3 deletions src/simulator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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 +128,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 +140,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 +157,7 @@
}

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

// Helper function to open a new tab
Expand All @@ -175,7 +181,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 184 in 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 +232,7 @@
}

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

Check warning on line 235 in 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 +281,7 @@
});
$("#bcdInput").on("keyup", function () {
var input = $("#bcdInput").val();
var num = 0;

Check warning on line 284 in 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
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, showMessage } 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)
showMessage(`"${fileName}" saved successfully to ${downloadDir}`)
SimulatorState.dialogBox.export_project_dialog = false
}
</script>
Expand Down
12 changes: 9 additions & 3 deletions v1/src/simulator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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 +128,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 +140,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 +157,7 @@ export async function downloadFileDesktop(
}

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

// Helper function to open a new tab
Expand Down
Loading