-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
68 lines (67 loc) · 1.71 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* MIT License
* Copyright © 2022 MarginNote
* Github: https://github.com/marginnoteapp/raycast-enhance
* Welcom to contribute to this project!
*/
try {
;(() => {
const Addon = {
name: "Raycast Enhance",
key: "raycastenhance"
}
const console = {
log(obj, suffix = "normal") {
JSB.log(`${Addon.key}-${suffix} %@`, obj)
}
}
const isMac = Application.sharedInstance().osType === 2
JSB.newAddon = mainPath => {
function fetchNotebook() {
try {
if (!isMac) return
const notebooks = Database.sharedInstance()
.allNotebooks()
.reduce((acc, k) => {
if (k.flags === 2 || k.flags === 3) {
acc.push({
id: k.topicId,
title: k.title,
lastVisit: k.lastVisit.getTime(),
type: k.flags === 2 ? 1 : 2
})
}
return acc
}, [])
NSData.dataWithStringEncoding(
JSON.stringify(notebooks),
4
).writeToFileAtomically(mainPath + "/notebooks.json", false)
} catch (err) {
console.log(err)
}
}
let isInNotebook = false
return JSB.defineClass(
Addon.name + ": JSExtension",
{
notebookWillClose() {
fetchNotebook()
}
},
{
addonDidConnect() {
if (
!NSFileManager.defaultManager().fileExistsAtPath(
mainPath + "/notebooks.json"
)
)
fetchNotebook()
}
}
)
}
})()
} catch (err) {
JSB.log("raycastenhance-error %@", String(err))
}