@@ -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,30 @@ 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 http = await import ( '@tauri-apps/plugin-http' )
276+ if ( http && http . fetch ) {
277+ fetchFn = http . fetch
278+ }
279+ } catch ( error ) {
280+ console . error ( 'Failed to load Tauri HTTP plugin:' , error )
281+ }
282+ }
283+
284+ fetchFn ( apiUrl , {
269285 method : 'POST' ,
270286 headers : {
271287 'Content-Type' : 'application/json' ,
@@ -276,6 +292,10 @@ export default function generateVerilogCircuit(
276292 if ( ! response . ok ) {
277293 throw response
278294 }
295+ const contentType = response . headers . get ( 'content-type' )
296+ if ( ! contentType || ! contentType . includes ( 'application/json' ) ) {
297+ throw new Error ( 'Invalid response from server (not JSON)' )
298+ }
279299 return response . json ( )
280300 } )
281301 . then ( ( circuitData ) => {
@@ -297,14 +317,18 @@ export default function generateVerilogCircuit(
297317 setVerilogOutput ( 'Verilog Circuit Successfully Created' , 'success' )
298318 } )
299319 . catch ( ( error ) => {
320+ console . error ( 'Verilog compilation error:' , error )
321+ showError ( 'Verilog compilation failed' )
300322 if ( error . status == 500 ) {
301- showError ( 'Could not connect to Yosys' )
302323 setVerilogOutput ( 'Could not connect to Yosys server' , 'error' )
303- } else {
304- showError ( 'There is some issue with the code' )
324+ } else if ( typeof error . json === 'function' ) {
305325 error . json ( ) . then ( ( errorMessage ) => {
306- setVerilogOutput ( errorMessage . message , 'error' )
326+ setVerilogOutput ( errorMessage . message || 'Unknown error' , 'error' )
327+ } ) . catch ( ( ) => {
328+ setVerilogOutput ( 'Error parsing error response' , 'error' )
307329 } )
330+ } else {
331+ setVerilogOutput ( error . message || 'Unknown error occurred' , 'error' )
308332 }
309333 } )
310334}
0 commit comments