Skip to content

Commit

Permalink
Fix duplications and extra search results on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
KELiON committed Feb 2, 2017
1 parent f83f9d7 commit ecf81b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 3 additions & 5 deletions app/main/plugins/core/basic-apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import { search } from 'cerebro-tools'
import uniq from 'lodash/uniq'
import initializeAsync from './initializeAsync'

const { openApp } = process.platform === 'win32'
const { openApp, toString } = process.platform === 'win32'
? require('./windows')
: require('./linux')

let appsList = []

const toString = (app) => `${app.name} ${app.filename}`

const fn = ({ term, actions, display }) => {
const result = search(appsList, term, toString).map(app => {
const { path, name, description } = app
const { id, path, name, description } = app
return {
id: path,
id: id || path,
title: name,
term: name,
subtitle: description || path,
Expand Down
15 changes: 14 additions & 1 deletion app/main/plugins/core/basic-apps/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import uniq from 'lodash/uniq'
import { shellCommand } from 'cerebro-tools'

let appDirs = [
path.join(remote.app.getPath('home'), '.local', 'share')
path.join(remote.app.getPath('home'), '.local', 'share'),
path.join('usr', 'share'),
path.join('usr', 'share', 'ubuntu'),
path.join('usr', 'share', 'gnome'),
path.join('usr', 'local', 'share'),
path.join('var', 'lib', 'snapd', 'desktop')
]

if (!!process.env.XDG_DATA_DIRS) {
Expand Down Expand Up @@ -42,6 +47,13 @@ const parseDesktopFile = (filePath, mapping) => {
}, {})
}

const getId = (filePath) => {
const match = filePath.match(/\/applications\/(.+)$/)
return match ? match[1] : filePath
}

export const toString = (app) => app.name

export const formatPath = (filePath) => {
const parsedData = parseDesktopFile(filePath, {
name: 'Name',
Expand All @@ -52,6 +64,7 @@ export const formatPath = (filePath) => {
return {
...parsedData,
filename,
id: getId(filePath),
name: parsedData.name || filename.replace(/\.(desktop)/, ''),
path: filePath
}
Expand Down
2 changes: 2 additions & 0 deletions app/main/plugins/core/basic-apps/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const EXTENSIONS = ['lnk', 'exe']

export const openApp = (appPath) => shell.openItem(appPath)

export const toString = (app) => `${app.name} ${app.filename}`

export const formatPath = (filePath) => ({
...parseFile(filePath),
filename: path.basename(filePath),
Expand Down

0 comments on commit ecf81b0

Please sign in to comment.