Skip to content

Commit

Permalink
Fix broken sub directories on Windows
Browse files Browse the repository at this point in the history
Don't use hard coded path separator 🤦
  • Loading branch information
heyman committed Jan 15, 2025
1 parent da523d7 commit e7e9f50
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions electron/preload/index.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -116,6 +117,8 @@ contextBridge.exposeInMainWorld("heynote", {
setLibraryPathChangeCallback(callback) {
ipcRenderer.on("library:pathChanged", callback)
},

pathSeparator: sep,
},

settings: CONFIG.get("settings"),
Expand Down
8 changes: 5 additions & 3 deletions src/components/BufferSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
}
})
Expand Down
10 changes: 6 additions & 4 deletions src/components/EditBuffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import FolderSelector from './folder-selector/FolderSelector.vue'
const pathSep = window.heynote.buffer.pathSeparator
export default {
data() {
return {
Expand Down Expand Up @@ -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 => {
Expand All @@ -51,7 +53,7 @@
if (node) {
currentLevel = node
} else {
const currentPath = currentParts.join("/")
const currentPath = currentParts.join(pathSep)
node = {
name: part,
children: [],
Expand All @@ -78,7 +80,7 @@
},
currentNoteDirectory() {
return this.currentBufferPath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split(pathSep).slice(0, -1).join(pathSep)
},
nameInputClass() {
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions src/components/NewBuffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import FolderSelector from './folder-selector/FolderSelector.vue'
const pathSep = window.heynote.buffer.pathSeparator
export default {
data() {
return {
Expand Down Expand Up @@ -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 => {
Expand All @@ -56,7 +58,7 @@
if (node) {
currentLevel = node
} else {
const currentPath = currentParts.join("/")
const currentPath = currentParts.join(pathSep)
node = {
name: part,
children: [],
Expand All @@ -80,7 +82,7 @@
]),
currentNoteDirectory() {
return this.currentBufferPath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split(pathSep).slice(0, -1).join(pathSep)
},
nameInputClass() {
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions src/components/folder-selector/FolderSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
})
Expand All @@ -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--
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions webapp/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ const Heynote = {
removeOnChangeCallback(path, callback) {

},

pathSeparator: "/",
},

mainProcess: {
Expand Down

0 comments on commit e7e9f50

Please sign in to comment.