vue-cli-plugin-electron-builder icon indicating copy to clipboard operation
vue-cli-plugin-electron-builder copied to clipboard

load dynamic image file from public folder after build

Open sharifcse57 opened this issue 1 year ago • 1 comments

I am using this plugin for a long time.. currently i facing issue for loading dynamic image file from public path after build.

sharifcse57 avatar Aug 07 '22 10:08 sharifcse57

try to use this

files in public folder, use src='local-media://test.png'

// in background.js
function registerLocalMediaProtocol() {
  protocol.registerFileProtocol('local-media', (request, callback) => {
    const url = request.url.replace(/^local-media:\/\//, '')
    // Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
    const decodedUrl = decodeURI(url) // Needed in case URL contains spaces
    try {
      return callback(path.join(__static, decodedUrl))
    } catch (error) {
      console.error(
        'ERROR: registerLocalMediaProtocol: Could not get file path:',
        error
      )
    }
  })
}

app.on('ready', async () => {
// ...
  registerLocalMediaProtocol()
// ...
}

klren0312 avatar Aug 08 '22 01:08 klren0312