diff --git a/electron/preload/index.js b/electron/preload/index.js index ce2aae8..800c12f 100644 --- a/electron/preload/index.js +++ b/electron/preload/index.js @@ -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"), diff --git a/src/components/BufferSelector.vue b/src/components/BufferSelector.vue index 200cbe7..a8e5f37 100644 --- a/src/components/BufferSelector.vue +++ b/src/components/BufferSelector.vue @@ -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, } }) diff --git a/src/components/EditBuffer.vue b/src/components/EditBuffer.vue index 4c03486..2ef8c1c 100644 --- a/src/components/EditBuffer.vue +++ b/src/components/EditBuffer.vue @@ -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" diff --git a/src/components/NewBuffer.vue b/src/components/NewBuffer.vue index 74b31ed..27bb986 100644 --- a/src/components/NewBuffer.vue +++ b/src/components/NewBuffer.vue @@ -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" diff --git a/src/components/folder-selector/FolderSelector.vue b/src/components/folder-selector/FolderSelector.vue index 30417e3..7676d51 100644 --- a/src/components/folder-selector/FolderSelector.vue +++ b/src/components/folder-selector/FolderSelector.vue @@ -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) diff --git a/webapp/bridge.js b/webapp/bridge.js index 632dc70..1d5f09f 100644 --- a/webapp/bridge.js +++ b/webapp/bridge.js @@ -217,6 +217,8 @@ const Heynote = { removeOnChangeCallback(path, callback) { }, + + pathSeparator: "/", }, mainProcess: {