-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
79 lines (70 loc) · 2.12 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
const fuzzyfind = require('fuzzyfind')
const Adapter = require('../../lib/adapter')
const mdfind = require('./mdfind')
const appQuery =
'(kMDItemContentType=com.apple.application-* || kMDItemContentType=com.apple.systempreference.prefpane)'
class MDFind extends Adapter {
findFiles (query) {
const { filePath, excludeName, excludePath } = this.env.directories
const options = {
cwd: this.cwd,
include: filePath,
exclude: excludeName.concat(excludePath),
}
return mdfind(query, options).then(files => {
return (this.env.matchBy === 'stringincludes'
? files.filter(obj => (obj.name + obj.path).toLowerCase().includes(query.toLowerCase()))
: fuzzyfind(query, files, {
accessor: function (obj) {
return obj.name + obj.path
},
})
)
.slice(0, 20)
.map(file => file.toJson())
})
}
findApps (query) {
const { appPath, excludeName, excludePath } = this.env.directories
const options = {
cwd: this.cwd,
include: appPath,
exclude: excludeName.concat(excludePath),
}
return mdfind(appQuery, options).then(files => {
return (this.env.matchBy === 'stringincludes'
? files.filter(obj => (obj.name + obj.path).toLowerCase().includes(query.toLowerCase()))
: fuzzyfind(query, files, {
accessor: function (obj) {
return obj.name + obj.path
},
})
)
.slice(0, 20)
.map(file => file.toJson())
})
}
cacheIcons (apps) {
return Promise.all(
apps
.filter(file => !file.hasIcon())
.slice(0, 20)
.map(file => file.generateIcon())
).then(() => apps)
}
startCache () {
const { appPath, excludeName, excludePath } = this.env.directories
const options = {
cwd: this.cwd,
include: appPath,
exclude: excludeName.concat(excludePath),
}
return mdfind(appQuery, options)
.then(apps => this.cacheIcons(apps))
.then(apps => apps.map(app => app.toJson()))
}
static isInstalled () {
return process.platform === 'darwin'
}
}
module.exports = MDFind