@@ -34,6 +34,7 @@ import { showError, showMessage } from './utils'
3434import { showProperties } from './ux'
3535import { useSimulatorMobileStore } from '#/store/simulatorMobileStore'
3636import { toRefs } from 'vue'
37+ import { isTauri } from '@tauri-apps/api/core'
3738
3839var editor
3940var verilogMode = false
@@ -257,15 +258,28 @@ export function YosysJSON2CV(
257258 }
258259}
259260
260- export default function generateVerilogCircuit (
261+ export default async function generateVerilogCircuit (
261262 verilogCode ,
262263 scope = globalScope
263264) {
264265 clearVerilogOutput ( )
265266 setVerilogOutput ( 'Compiling Verilog code...' , 'info' )
266267
267268 var params = { code : verilogCode }
268- fetch ( '/api/v1/simulator/verilogcv' , {
269+ let apiUrl = '/api/v1/simulator/verilogcv'
270+ let fetchFn = window . fetch
271+
272+ if ( isTauri ( ) ) {
273+ apiUrl = `https://circuitverse.org${ apiUrl } `
274+ try {
275+ const { fetch } = await import ( '@tauri-apps/plugin-http' )
276+ fetchFn = fetch
277+ } catch ( error ) {
278+ console . error ( 'Failed to load Tauri HTTP plugin:' , error )
279+ }
280+ }
281+
282+ fetchFn ( apiUrl , {
269283 method : 'POST' ,
270284 headers : {
271285 'Content-Type' : 'application/json' ,
@@ -276,6 +290,10 @@ export default function generateVerilogCircuit(
276290 if ( ! response . ok ) {
277291 throw response
278292 }
293+ const contentType = response . headers . get ( 'content-type' )
294+ if ( ! contentType || ! contentType . includes ( 'application/json' ) ) {
295+ throw new Error ( 'Invalid response from server (not JSON)' )
296+ }
279297 return response . json ( )
280298 } )
281299 . then ( ( circuitData ) => {
@@ -297,14 +315,18 @@ export default function generateVerilogCircuit(
297315 setVerilogOutput ( 'Verilog Circuit Successfully Created' , 'success' )
298316 } )
299317 . catch ( ( error ) => {
318+ console . error ( 'Verilog compilation error:' , error )
319+ showError ( 'Verilog compilation failed' )
300320 if ( error . status == 500 ) {
301- showError ( 'Could not connect to Yosys' )
302321 setVerilogOutput ( 'Could not connect to Yosys server' , 'error' )
303- } else {
304- showError ( 'There is some issue with the code' )
322+ } else if ( typeof error . json === 'function' ) {
305323 error . json ( ) . then ( ( errorMessage ) => {
306- setVerilogOutput ( errorMessage . message , 'error' )
324+ setVerilogOutput ( errorMessage . message || 'Unknown error' , 'error' )
325+ } ) . catch ( ( ) => {
326+ setVerilogOutput ( 'Error parsing error response' , 'error' )
307327 } )
328+ } else {
329+ setVerilogOutput ( error . message || 'Unknown error occurred' , 'error' )
308330 }
309331 } )
310332}
0 commit comments