Fix broken sub directories on Windows

Don't use hard coded path separator 🤦
This commit is contained in:
Jonatan Heyman 2025-01-15 14:06:33 +01:00
parent da523d70e7
commit ee06b01b60
6 changed files with 27 additions and 14 deletions

View File

@ -1,4 +1,5 @@
const { contextBridge } = require('electron')
import { sep } from "path"
import themeMode from "./theme-mode"
import { isMac, isWindows, isLinux, isDev } from "../detect-platform"
import { ipcRenderer } from "electron"
@ -116,6 +117,8 @@ contextBridge.exposeInMainWorld("heynote", {
setLibraryPathChangeCallback(callback) {
ipcRenderer.on("library:pathChanged", callback)
},
pathSeparator: sep,
},
settings: CONFIG.get("settings"),

View File

@ -5,6 +5,8 @@
import { SCRATCH_FILE_NAME } from "../common/constants"
import { useHeynoteStore } from "../stores/heynote-store"
const pathSep = window.heynote.buffer.pathSeparator
export default {
props: {
headline: String,
@ -47,8 +49,8 @@
return sortScore
} else {
// then notes in root
const aIsRoot = a.path.indexOf("/") === -1
const bIsRoot = b.path.indexOf("/") === -1
const aIsRoot = a.path.indexOf(pathSep) === -1
const bIsRoot = b.path.indexOf(pathSep) === -1
if (aIsRoot && !bIsRoot) {
return -1
} else if (!aIsRoot && bIsRoot) {
@ -105,7 +107,7 @@
return {
"path": path,
"name": metadata?.name || path,
"folder": path.split("/").slice(0, -1).join("/"),
"folder": path.split(pathSep).slice(0, -1).join(pathSep),
"scratch": path === SCRATCH_FILE_NAME,
}
})

View File

@ -7,6 +7,8 @@
import FolderSelector from './folder-selector/FolderSelector.vue'
const pathSep = window.heynote.buffer.pathSeparator
export default {
data() {
return {
@ -42,7 +44,7 @@
const getNodeFromList = (list, part) => list.find(node => node.name === part)
directories.forEach((path) => {
const parts = path.split("/")
const parts = path.split(pathSep)
let currentLevel = rootNode
let currentParts = []
parts.forEach(part => {
@ -51,7 +53,7 @@
if (node) {
currentLevel = node
} else {
const currentPath = currentParts.join("/")
const currentPath = currentParts.join(pathSep)
node = {
name: part,
children: [],
@ -78,7 +80,7 @@
},
currentNoteDirectory() {
return this.currentBufferPath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split(pathSep).slice(0, -1).join(pathSep)
},
nameInputClass() {
@ -132,7 +134,7 @@
this.errors.name = true
return
}
const parentPathPrefix = this.parentPath === "" ? "" : this.parentPath + "/"
const parentPathPrefix = this.parentPath === "" ? "" : this.parentPath + pathSep
let path;
for (let i=0; i<1000; i++) {
let filename = slug + ".txt"

View File

@ -6,6 +6,8 @@
import FolderSelector from './folder-selector/FolderSelector.vue'
const pathSep = window.heynote.buffer.pathSeparator
export default {
data() {
return {
@ -47,7 +49,7 @@
const getNodeFromList = (list, part) => list.find(node => node.name === part)
directories.forEach((path) => {
const parts = path.split("/")
const parts = path.split(pathSep)
let currentLevel = rootNode
let currentParts = []
parts.forEach(part => {
@ -56,7 +58,7 @@
if (node) {
currentLevel = node
} else {
const currentPath = currentParts.join("/")
const currentPath = currentParts.join(pathSep)
node = {
name: part,
children: [],
@ -80,7 +82,7 @@
]),
currentNoteDirectory() {
return this.currentBufferPath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split(pathSep).slice(0, -1).join(pathSep)
},
nameInputClass() {
@ -140,7 +142,7 @@
this.errors.name = true
return
}
const parentPathPrefix = this.parentPath === "" ? "" : this.parentPath + "/"
const parentPathPrefix = this.parentPath === "" ? "" : this.parentPath + pathSep
let path;
for (let i=0; i<1000; i++) {
let filename = slug + ".txt"

View File

@ -2,6 +2,8 @@
import FolderItem from "./FolderItem.vue"
import NewFolderItem from "./NewFolderItem.vue"
const pathSep = window.heynote.buffer.pathSeparator
export default {
props: {
directoryTree: Object,
@ -144,7 +146,7 @@
node.createNewFolder = false
node.children.unshift({
name: name,
path: parentPath === "" ? name : parentPath + "/" + name,
path: parentPath === "" ? name : parentPath + pathSep + name,
children: [],
newFolder: true,
})
@ -163,7 +165,7 @@
//console.log("Remove newly created folder:", path)
const node = this.getNode(path)
if (node.newFolder && path) {
const parentPath = path.split("/").slice(0, -1).join("/")
const parentPath = path.split(pathSep).slice(0, -1).join(pathSep)
const parent = this.getNode(parentPath)
parent.children = parent.children.filter(child => child.path !== path)
this.selected--
@ -173,7 +175,7 @@
getNode(path) {
const getNodeFromList = (list, part) => list.find(node => node.name === part)
const parts = path.split("/")
const parts = path.split(pathSep)
let currentLevel = this.tree
for (const part of parts) {
const node = getNodeFromList(currentLevel.children, part)

View File

@ -217,6 +217,8 @@ const Heynote = {
removeOnChangeCallback(path, callback) {
},
pathSeparator: "/",
},
mainProcess: {