Skip to content

Commit

Permalink
Fix open app on linux
Browse files Browse the repository at this point in the history
Use shell.openExternal on windows and exec from .desktop file on linux
  • Loading branch information
KELiON committed Feb 2, 2017
1 parent b084a5e commit 96caacd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
11 changes: 7 additions & 4 deletions app/main/plugins/core/basic-apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,7 +28,7 @@ const fn = ({ term, actions, display }) => {
event.preventDefault()
}
},
onSelect: () => shell.openItem(path),
onSelect: () => openApp(app),
getPreview: () => <Preview name={name} path={path} />
}
})
Expand Down
2 changes: 1 addition & 1 deletion app/main/plugins/core/basic-apps/initializeAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
3 changes: 3 additions & 0 deletions app/main/plugins/core/basic-apps/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) => {
Expand Down
19 changes: 18 additions & 1 deletion app/main/plugins/core/basic-apps/windows.js
Original file line number Diff line number Diff line change
@@ -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\\`,
Expand All @@ -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)/, ''),
})

0 comments on commit 96caacd

Please sign in to comment.