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

    Access Capacitor API from store action ?

    Help
    4
    7
    852
    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.
    • tlloyduk
      tlloyduk last edited by tlloyduk

      Hi,
      Is it possible to access a Capacitor API e.g. Storage, from a Quasar store module action ?
      I’m trying to populate state from Storage on app load (through prefetch) but I can’t seem to reference @capacitor/core.

      I was trying to do something like this in a store action (but it can’t get the dependency reference to capacitor/core)

      import { Plugins } from '@capacitor/core'
      
      const { Storage } = Plugins
      
      export function getCompanyId (context) {
        const { companyId } = Storage.get({ key: 'companyId' })
        context.commit('companyId', companyId)
      }
      
      

      … but keep being met with errors like this even after playing around with the path

      This dependency was not found:
      
      * @capacitor/core in ./src/store/appConfig/index.js, ./src/store/appConfig/actions.js
      

      Anyone done anything similar or can suggest a better approach?

      metalsadman 1 Reply Last reply Reply Quote 0
      • tlloyduk
        tlloyduk last edited by

        OK seems like it does work fine, it just won’t work with SPA build… doing some more tests

        1 Reply Last reply Reply Quote 0
        • metalsadman
          metalsadman @tlloyduk last edited by

          @tlloyduk since the dep is inside your src-capacitor/node_modules, you can use a relative path, or register an alias in quasar.conf.js to said folder. ie. import { Plugins } from 'someAliasToSrcCapacitorNodeModulesFolder/@capacitor/core'. tested on dev, but not sure if this work on production.

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

            Thanks metalsadman, I might experiment with that to see if I can run the app without the emulator for rapid dev

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

              Using the app alias worked, e.g.
              import { Plugins } from 'app/src-capacitor/node_modules/@capacitor/core'

              Thanks

              1 Reply Last reply Reply Quote 1
              • M
                Marin Vartan last edited by Marin Vartan

                Thank you @tlloyduk
                i use this line

                import { Plugins } from '../../src-capacitor/node_modules/@capacitor/core';
                
                J 1 Reply Last reply Reply Quote 0
                • J
                  jadedRepublic @Marin Vartan last edited by

                  @Marin-Vartan Is there any reason not to install It separately outside src-capacitor?

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