Skip to content

Commit 8df051d

Browse files
committed
Fix Windows file URLs and natural media sorting
1 parent b7822e5 commit 8df051d

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

electron/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path'
33
import fs from 'fs'
44
import http from 'http'
55
import https from 'https'
6-
import { URL } from 'url'
6+
import { URL, pathToFileURL } from 'url'
77
import { OsrSerialManager } from './osrSerial'
88
import { SCRIPT_AXIS_DEFINITIONS, inferAxisIdFromStem, stripKnownAxisSuffix } from '../src/services/multiaxis'
99
import { getVideoSubtitleMatchScore, parseSubtitleFile } from '../src/services/subtitles'
@@ -43,6 +43,7 @@ const SUBTITLE_DIR_KEYWORDS = [
4343
const MAX_SUBTITLE_SEARCH_DEPTH = 2
4444
const MAX_SCAN_SUBTITLE_VALIDATION_CANDIDATES = 3
4545
const SCAN_YIELD_INTERVAL = 25
46+
const NATURAL_SORTER = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
4647

4748
let mainWindow: BrowserWindow | null = null
4849
const subtitleCandidateCache = new Map<string, string[]>()
@@ -198,7 +199,7 @@ ipcMain.handle('fs:readDir', async (_event, dirPath: string) => {
198199
}
199200

200201
await scanDir(dirPath, '')
201-
return files.sort((a, b) => a.relativePath.localeCompare(b.relativePath))
202+
return files.sort((a, b) => NATURAL_SORTER.compare(a.relativePath, b.relativePath))
202203
} catch {
203204
return []
204205
}
@@ -226,8 +227,8 @@ ipcMain.handle('fs:saveFunscript', async (_event, videoPath: string, data: strin
226227
})
227228

228229
ipcMain.handle('fs:getVideoUrl', async (_event, filePath: string) => {
229-
// Return a file:// URL that the renderer can use
230-
return `file:///${filePath.replace(/\\/g, '/')}`
230+
// Encode reserved URL characters such as "#" in Windows file names.
231+
return pathToFileURL(filePath).toString()
231232
})
232233

233234
ipcMain.handle('fs:findArtwork', async (_event, mediaPath: string) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptplayer-plus",
3-
"version": "0.1.5-exp.4",
3+
"version": "0.1.5-exp.6",
44
"description": "ScriptPlayer+ - Funscript video player with Handy and Intiface support",
55
"license": "PolyForm-Noncommercial-1.0.0",
66
"main": "dist-electron/main.js",

scripts/set-icon.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const ResEdit = require('resedit')
44

55
const pkg = require('../package.json')
66

7-
const exe = path.join(__dirname, '..', 'release', 'win-unpacked', 'ScriptPlayerPlus.exe')
7+
const outputDir = process.argv[2] || process.env.BUILD_OUTPUT_DIR || 'release'
8+
const exe = path.join(__dirname, '..', outputDir, 'win-unpacked', 'ScriptPlayerPlus.exe')
89
const ico = path.join(__dirname, '..', 'public', 'icon.ico')
910

1011
if (!fs.existsSync(exe)) {

src/components/Sidebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ interface FolderGroup {
102102
files: VideoFile[]
103103
}
104104

105+
const NATURAL_SORTER = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
106+
105107
function groupByFolder(files: VideoFile[]): FolderGroup[] {
106108
const map = new Map<string, VideoFile[]>()
107109
for (const file of files) {
@@ -115,7 +117,7 @@ function groupByFolder(files: VideoFile[]): FolderGroup[] {
115117
for (const [folder, folderFiles] of map) {
116118
groups.push({ folder, files: folderFiles })
117119
}
118-
groups.sort((a, b) => a.folder.localeCompare(b.folder))
120+
groups.sort((a, b) => NATURAL_SORTER.compare(a.folder, b.folder))
119121
return groups
120122
}
121123

0 commit comments

Comments
 (0)