diff --git a/app/main/plugins/core/basic-apps/index.js b/app/main/plugins/core/basic-apps/index.js index 85e455c1..c27f01f6 100644 --- a/app/main/plugins/core/basic-apps/index.js +++ b/app/main/plugins/core/basic-apps/index.js @@ -3,15 +3,18 @@ import Preview from './Preview' import { search } from 'cerebro-tools' import uniq from 'lodash/uniq' import initializeAsync from './initializeAsync' -import { shell } from 'electron' + +const { openApp } = 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(file => { - const { path, name, description } = file + const result = search(appsList, term, toString).map(app => { + const { path, name, description } = app return { id: path, title: name, @@ -25,7 +28,7 @@ const fn = ({ term, actions, display }) => { event.preventDefault() } }, - onSelect: () => shell.openItem(path), + onSelect: () => openApp(app), getPreview: () => } }) diff --git a/app/main/plugins/core/basic-apps/initializeAsync.js b/app/main/plugins/core/basic-apps/initializeAsync.js index a6b8e8b1..b5bdb63e 100644 --- a/app/main/plugins/core/basic-apps/initializeAsync.js +++ b/app/main/plugins/core/basic-apps/initializeAsync.js @@ -36,7 +36,7 @@ export default (callback) => { }) const searchApps = () => getAppsList().then(apps => { - const json = JSON.stringify(process.env.NODE_ENV) + const json = JSON.stringify(apps) fs.writeFile(CACHE_FILE, json, cacheOptions) callback(apps) }) diff --git a/app/main/plugins/core/basic-apps/linux.js b/app/main/plugins/core/basic-apps/linux.js index 529a9619..2ffc38c6 100644 --- a/app/main/plugins/core/basic-apps/linux.js +++ b/app/main/plugins/core/basic-apps/linux.js @@ -2,6 +2,7 @@ import { remote } from 'electron' import path from 'path' import fs from 'fs' import uniq from 'lodash/uniq' +import { shellCommand } from 'cerebro-tools' let appDirs = [ path.join(remote.app.getPath('home'), '.local', 'share') @@ -23,6 +24,8 @@ export const DIRECTORIES = uniq([ export const EXTENSIONS = ['desktop'] +export const openApp = (app) => shellCommand(app.exec) + const parseDesktopFile = (filePath, mapping) => { const content = fs.readFileSync(filePath, 'utf-8') return Object.keys(mapping).reduce((acc, key) => { diff --git a/app/main/plugins/core/basic-apps/windows.js b/app/main/plugins/core/basic-apps/windows.js index 7934f756..dbb87c02 100644 --- a/app/main/plugins/core/basic-apps/windows.js +++ b/app/main/plugins/core/basic-apps/windows.js @@ -1,7 +1,22 @@ import path from 'path' +import { shell } from 'electron' const { APPDATA, ProgramData, USERPROFILE } = process.env +const parseFile = (filePath) => { + try { + const details = shell.readShortcutLink(filePath) + return { + path: details.target, + description: details.description + } + } catch (e) { + return { + path: filePath + } + } +} + export const DIRECTORIES = [ USERPROFILE && `${USERPROFILE}\\Desktop\\`, APPDATA && `${APPDATA}\\Microsoft\\Windows\\Start Menu\\Programs\\`, @@ -10,8 +25,10 @@ export const DIRECTORIES = [ export const EXTENSIONS = ['lnk', 'exe'] +export const openApp = (appPath) => shell.openItem(appPath) + export const formatPath = (filePath) => ({ - path: filePath, + ...parseFile(filePath), filename: path.basename(filePath), name: path.basename(filePath).replace(/\.(exe|lnk)/, ''), })