No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Interacting with local files

    Help
    6
    7
    5988
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mmarquez last edited by

      Hi!

      Hope this is the correct forum to post this question.

      I created a simple web app that generates { entries } and save them in an [ array ]. All this works perfectly in the browser.

      My next step is to integrate ‘fs’ (or similar) to be able to work with real data. Basically my idea is to generate the data and being able to save it into the desktop. At the same time to open the generated file (json) and render it for further edits.

      Any tips on how to approach this problem? I’m aware fs can only run in the electron side – but I can’t find a lot of documentation on how to set this up and still interact with it through the vue/client side.

      Thanks!

      1 Reply Last reply Reply Quote 0
      • rstoenescu
        rstoenescu Admin last edited by

        Hi,

        So are you building an Electron app or are you making a website?

        1 Reply Last reply Reply Quote 0
        • M
          mmarquez last edited by

          Hi!

          Building an Electron App with ‘fs’ capabilities – would like to use the Quasar framework for this project. Thanks!

          1 Reply Last reply Reply Quote 0
          • G
            Gatsbill last edited by Gatsbill

            Don’t have time to give you a proper exemple now, sorry for that, but I think you have to use : https://electron.atom.io/docs/api/ipc-main/

            Its a process that send message from main process to renderer process (or renderer to main). So if you want to use fs node module you can do something like (didn’t test it, just a quick heads up) :

            // In main process.
            const {ipcMain} = require('electron')
            const fs = require('fs')
            const path = require('path')
            
            ipcMain.on('get-json', (event, filePath) => {
             const formatedPath = path.join(__dirname, filePath)
             fs.readFile(formatedPath, 'utf8', (err, data) => {
                if (err) 
                   // error handling
            
                const jsonFile = JSON.parse(data)
                event.sender.send('get-json-reply', jsonFile)
              })
            })
            
            ipcMain.on('generate-data', (event, data, filePath) => {
              const formatedPath = path.join(__dirname, filePath)
              fs.writeFile(formatedPath, JSON.stringify(data, null, 2) , 'utf-8', (err) => {
                 if (err) 
                   // error handling
                  event.sender.send('generate-data-reply')
              });
            })
            
            // In renderer process (web page).
            const {ipcRenderer} = require('electron')
            
            ipcRenderer.send('generate-data', {hello: 'world'}, './test/test.json');
            
            ipcRenderer.on('generate-data-reply', (event, arg) => {
               // do whaterver you want
              console.log(ipcRenderer.sendSync('get-json', './test/test.json'));
            })
            
            1 Reply Last reply Reply Quote 0
            • L
              lbssousa last edited by

              Maybe this can give you some light: http://forum.quasar-framework.org/topic/384/help-loading-local-json-file-in-either-web-or-electron-contexts

              1 Reply Last reply Reply Quote 0
              • M
                monkeyslippery last edited by

                This does not work for me, i’m currently needing to save files to disk…
                Trying to use “fs” it gives me: To install it, you can run: npm install --save fs

                1 Reply Last reply Reply Quote 0
                • benoitranque
                  benoitranque last edited by

                  this stackoverflow question can help you

                  Be sure to install the packages, and remember you cannot access the filesystem if you are not running electron

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post