diff --git a/package.json b/package.json index f12d2f8..6babd98 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,6 @@ "electron-window-state": "^5.0.2", "entypo": "^2.1.0", "existy": "^1.0.1", - "file-url": "^3.0.0", "flush-write-stream": "^2.0.0", "folder-walker": "^3.2.0", "format-duration": "^3.0.2", @@ -110,7 +109,7 @@ "common-shakeify": "^1.1.2", "concat-stream": "^2.0.0", "dependency-check": "^4.1.0", - "electron": "^27.0.1", + "electron": "^28.0.0", "electron-builder": "^24.4.0", "electron-renderify": "0.0.2", "envify": "^4.1.0", diff --git a/renderer/audio/index.js b/renderer/audio/index.js index 4baf89a..a2e9f1f 100644 --- a/renderer/audio/index.js +++ b/renderer/audio/index.js @@ -7,7 +7,7 @@ const path = require('path') const mainState = remote.require('./index.js') const needle = 'file://' + path.resolve(__dirname, 'needle.mp3') let startupNode = document.querySelector('#needle') -const fileUrlFromPath = require('file-url') +const fileUrlFromPath = require('../shared/file-url') needleSound(startupNode, needle, mainState.volume, mainState.muted) diff --git a/renderer/player/elements/player/artwork.js b/renderer/player/elements/player/artwork.js index 33bc65a..771d1d4 100644 --- a/renderer/player/elements/player/artwork.js +++ b/renderer/player/elements/player/artwork.js @@ -1,6 +1,6 @@ const html = require('choo/html') const Component = require('nanocomponent') -const fileUrlFromPath = require('file-url') +const fileUrlFromPath = require('../../../shared/file-url') const path = require('path') const defaultBG = path.resolve(window.__dirname, 'default-artwork.png') const compare = require('nanocomponent/compare') diff --git a/renderer/shared/file-url.js b/renderer/shared/file-url.js new file mode 100644 index 0000000..84892ef --- /dev/null +++ b/renderer/shared/file-url.js @@ -0,0 +1,30 @@ +const path = require('path') + +// Vendored from https://github.com/sindresorhus/file-url/blob/982123e9af861ce26167de7ef40be3ff9cad2be7/index.js#L2 +// because inconvient ESM upgrade + +function fileUrl (filePath, options = {}) { + if (typeof filePath !== 'string') { + throw new TypeError(`Expected a string, got ${typeof filePath}`) + } + + const { resolve = true } = options + + let pathName = filePath + if (resolve) { + pathName = path.resolve(filePath) + } + + pathName = pathName.replace(/\\/g, '/') + + // Windows drive letter must be prefixed with a slash. + if (pathName[0] !== '/') { + pathName = `/${pathName}` + } + + // Escape required characters for path components. + // See: https://tools.ietf.org/html/rfc3986#section-3.3 + return encodeURI(`file://${pathName}`).replace(/[?#]/g, encodeURIComponent) +} + +module.exports = fileUrl