-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54ed343
commit e44ae48
Showing
7 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,9 @@ export let config = { | |
active: true, | ||
quality: 1.0, | ||
}, | ||
locate: { | ||
active: true, | ||
}, | ||
}, | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
import { stringMatchQuality } from "../../common/util"; | ||
import { config } from "../config"; | ||
import { stat, exists, readdir } from "fs"; | ||
import path from 'path'; | ||
import { exec } from "child_process"; | ||
import { app } from "electron"; | ||
|
||
const LocateModule = { | ||
valid: (query) => { | ||
return config.modules.locate.active && query.length >= 1; | ||
}, | ||
search: (query) => { | ||
return new Promise((resolve) => { | ||
exec(`locate -i -e -b ${query}`, async (_, stdout, __) => { | ||
if(stdout) { | ||
resolve(await Promise.all(stdout.split('\n').map((file) => { | ||
return new Promise(async (resolve) => { | ||
let option = { | ||
type: 'icon_list_item', | ||
uri_icon: (await app.getFileIcon(file)).toDataURL(), | ||
primary: path.basename(file), | ||
secondary: file, | ||
executable: true, | ||
quality: query[query.length - 1] === '/' ? 0.25 : 0.5 * stringMatchQuality(path.basename(query), path.basename(file)), | ||
file: file, | ||
}; | ||
resolve(option); | ||
}); | ||
}))); | ||
} else { | ||
resolve([]); | ||
} | ||
}); | ||
}); | ||
}, | ||
execute: (option) => { | ||
return new Promise((resolve) => { | ||
exec(`xdg-open ${option.file}`, () => { | ||
resolve(); | ||
}) | ||
}); | ||
}, | ||
} | ||
|
||
export default LocateModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters