mirror of
https://github.com/heyman/heynote.git
synced 2024-11-22 16:03:28 +01:00
Throw error if major format version is greater than the currently supported version
This commit is contained in:
parent
8f39b6687e
commit
68c741ea46
98
package-lock.json
generated
98
package-lock.json
generated
@ -9,7 +9,8 @@
|
|||||||
"version": "1.8.0",
|
"version": "1.8.0",
|
||||||
"license": "Commons Clause MIT",
|
"license": "Commons Clause MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-log": "^5.0.1"
|
"electron-log": "^5.0.1",
|
||||||
|
"semver": "^7.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@codemirror/autocomplete": "^6.11.1",
|
"@codemirror/autocomplete": "^6.11.1",
|
||||||
@ -572,6 +573,15 @@
|
|||||||
"global-agent": "^3.0.0"
|
"global-agent": "^3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@electron/get/node_modules/semver": {
|
||||||
|
"version": "6.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
||||||
|
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"semver": "bin/semver.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@electron/universal": {
|
"node_modules/@electron/universal": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/@electron/universal/-/universal-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/@electron/universal/-/universal-1.2.1.tgz",
|
||||||
@ -2089,21 +2099,6 @@
|
|||||||
"graceful-fs": "^4.1.6"
|
"graceful-fs": "^4.1.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/app-builder-lib/node_modules/semver": {
|
|
||||||
"version": "7.5.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
|
||||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/app-builder-lib/node_modules/universalify": {
|
"node_modules/app-builder-lib/node_modules/universalify": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
||||||
@ -2721,21 +2716,6 @@
|
|||||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/conf/node_modules/semver": {
|
|
||||||
"version": "7.5.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
|
||||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/core-util-is": {
|
"node_modules/core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
@ -3465,21 +3445,6 @@
|
|||||||
"graceful-fs": "^4.1.6"
|
"graceful-fs": "^4.1.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/electron-updater/node_modules/semver": {
|
|
||||||
"version": "7.5.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
|
||||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/electron-updater/node_modules/universalify": {
|
"node_modules/electron-updater/node_modules/universalify": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
|
||||||
@ -3914,22 +3879,6 @@
|
|||||||
"node": ">=10.0"
|
"node": ">=10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/global-agent/node_modules/semver": {
|
|
||||||
"version": "7.5.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
|
||||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
|
||||||
"dev": true,
|
|
||||||
"optional": true,
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/globalthis": {
|
"node_modules/globalthis": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.3.tgz",
|
||||||
@ -5367,12 +5316,14 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/semver": {
|
"node_modules/semver": {
|
||||||
"version": "6.3.1",
|
"version": "7.6.3",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
|
||||||
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
|
"integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==",
|
||||||
"dev": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"semver": "bin/semver.js"
|
"semver": "bin/semver.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/semver-compare": {
|
"node_modules/semver-compare": {
|
||||||
@ -6388,21 +6339,6 @@
|
|||||||
"typescript": "*"
|
"typescript": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vue-tsc/node_modules/semver": {
|
|
||||||
"version": "7.5.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
|
|
||||||
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/w3c-keyname": {
|
"node_modules/w3c-keyname": {
|
||||||
"version": "2.2.8",
|
"version": "2.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
|
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
"vue-tsc": "^1.0.16"
|
"vue-tsc": "^1.0.16"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-log": "^5.0.1"
|
"electron-log": "^5.0.1",
|
||||||
|
"semver": "^7.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,35 +58,40 @@
|
|||||||
|
|
||||||
// load buffer content and create editor
|
// load buffer content and create editor
|
||||||
window.heynote.buffer.load().then((content) => {
|
window.heynote.buffer.load().then((content) => {
|
||||||
let diskContent = content
|
try {
|
||||||
this.editor = new HeynoteEditor({
|
let diskContent = content
|
||||||
element: this.$refs.editor,
|
this.editor = new HeynoteEditor({
|
||||||
content: content,
|
element: this.$refs.editor,
|
||||||
theme: this.theme,
|
content: content,
|
||||||
saveFunction: (content) => {
|
theme: this.theme,
|
||||||
if (content === diskContent) {
|
saveFunction: (content) => {
|
||||||
return
|
if (content === diskContent) {
|
||||||
}
|
return
|
||||||
diskContent = content
|
}
|
||||||
window.heynote.buffer.save(content)
|
diskContent = content
|
||||||
},
|
window.heynote.buffer.save(content)
|
||||||
keymap: this.keymap,
|
},
|
||||||
emacsMetaKey: this.emacsMetaKey,
|
keymap: this.keymap,
|
||||||
showLineNumberGutter: this.showLineNumberGutter,
|
emacsMetaKey: this.emacsMetaKey,
|
||||||
showFoldGutter: this.showFoldGutter,
|
showLineNumberGutter: this.showLineNumberGutter,
|
||||||
bracketClosing: this.bracketClosing,
|
showFoldGutter: this.showFoldGutter,
|
||||||
fontFamily: this.fontFamily,
|
bracketClosing: this.bracketClosing,
|
||||||
fontSize: this.fontSize,
|
fontFamily: this.fontFamily,
|
||||||
})
|
fontSize: this.fontSize,
|
||||||
window._heynote_editor = this.editor
|
})
|
||||||
window.document.addEventListener("currenciesLoaded", this.onCurrenciesLoaded)
|
window._heynote_editor = this.editor
|
||||||
this.editor.setDefaultBlockLanguage(this.defaultBlockLanguage, this.defaultBlockLanguageAutoDetect)
|
window.document.addEventListener("currenciesLoaded", this.onCurrenciesLoaded)
|
||||||
|
this.editor.setDefaultBlockLanguage(this.defaultBlockLanguage, this.defaultBlockLanguageAutoDetect)
|
||||||
|
|
||||||
// set up buffer change listener
|
// set up buffer change listener
|
||||||
window.heynote.buffer.onChangeCallback((event, content) => {
|
window.heynote.buffer.onChangeCallback((event, content) => {
|
||||||
diskContent = content
|
diskContent = content
|
||||||
this.editor.setContent(content)
|
this.editor.setContent(content)
|
||||||
})
|
})
|
||||||
|
} catch (e) {
|
||||||
|
alert("Error! " + e.message)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// set up window close handler that will save the buffer and quit
|
// set up window close handler that will save the buffer and quit
|
||||||
window.heynote.onWindowClose(() => {
|
window.heynote.onWindowClose(() => {
|
||||||
|
@ -136,9 +136,14 @@ export class HeynoteEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContent(content) {
|
setContent(content) {
|
||||||
return new Promise((resolve) => {
|
try {
|
||||||
this.note = NoteFormat.load(content)
|
this.note = NoteFormat.load(content)
|
||||||
|
this.setReadOnly(false)
|
||||||
|
} catch (e) {
|
||||||
|
this.setReadOnly(true)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
return new Promise((resolve) => {
|
||||||
// set buffer content
|
// set buffer content
|
||||||
this.view.dispatch({
|
this.view.dispatch({
|
||||||
changes: {
|
changes: {
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
|
import { major } from "semver";
|
||||||
|
|
||||||
|
|
||||||
|
const FORMAT_VERSION = "1.0.0"
|
||||||
|
|
||||||
|
|
||||||
export class NoteFormat {
|
export class NoteFormat {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.content = '';
|
this.content = '';
|
||||||
this.metadata = {};
|
this.metadata = {formatVersion: "0.0.0"};
|
||||||
}
|
}
|
||||||
|
|
||||||
static load(data) {
|
static load(data) {
|
||||||
@ -17,11 +23,15 @@ export class NoteFormat {
|
|||||||
note.content = data.slice(firstSeparator)
|
note.content = data.slice(firstSeparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (major(note.metadata.formatVersion) > major(FORMAT_VERSION)) {
|
||||||
|
throw new Error(`Unsupported Heynote format version: ${note.metadata.formatVersion}. You probably need to update Heynote.`)
|
||||||
|
}
|
||||||
|
|
||||||
return note
|
return note
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize() {
|
serialize() {
|
||||||
this.metadata.formatVersion = "1.0"
|
this.metadata.formatVersion = FORMAT_VERSION
|
||||||
return JSON.stringify(this.metadata) + this.content
|
return JSON.stringify(this.metadata) + this.content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user