-
Notifications
You must be signed in to change notification settings - Fork 45
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
Showing
8 changed files
with
2,382 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
env: { | ||
commonjs: true, | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'airbnb-base', | ||
], | ||
globals: { | ||
Atomics: 'readonly', | ||
SharedArrayBuffer: 'readonly', | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
}, | ||
rules: { | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
node_modules | ||
dist | ||
*.tgz |
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,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,16 +1,95 @@ | ||
const { resolve } = require('path'); | ||
const { app, Menu, Tray } = require('electron') | ||
const { resolve, basename } = require('path'); | ||
const { | ||
app, Menu, Tray, dialog, | ||
} = require('electron'); | ||
const { spawn } = require('child_process'); | ||
const Store = require('electron-store'); | ||
const Sentry = require('@sentry/electron'); | ||
const fixPath = require('fix-path'); | ||
|
||
app.dock.hide() | ||
fixPath(); | ||
|
||
app.on('ready', () => { | ||
const tray = new Tray(resolve(__dirname, 'assets', 'iconTemplate.png')); | ||
Sentry.init({ dsn: 'https://[email protected]/1506479' }); | ||
|
||
const schema = { | ||
projects: { | ||
type: 'string', | ||
}, | ||
}; | ||
|
||
const store = new Store({ schema }); | ||
|
||
app.dock.hide(); | ||
|
||
function render(tray) { | ||
const storedProjects = store.get('projects'); | ||
const projects = storedProjects ? JSON.parse(storedProjects) : []; | ||
|
||
const items = projects.map(project => ({ | ||
label: project.name, | ||
submenu: [ | ||
{ | ||
label: 'Abrir no VSCode', | ||
click: () => { | ||
spawn('code', [project.path], { | ||
cwd: process.cwd(), | ||
env: { | ||
PATH: process.env.PATH, | ||
}, | ||
stdio: 'inherit', | ||
}); | ||
}, | ||
}, | ||
{ | ||
label: 'Remover', | ||
click: () => { | ||
store.set('projects', JSON.stringify(projects.filter(item => item.path !== project.path))); | ||
|
||
render(); | ||
}, | ||
}, | ||
], | ||
})); | ||
|
||
const contextMenu = Menu.buildFromTemplate([ | ||
{ label: 'Item1', type: 'radio', checked: true } | ||
{ | ||
label: 'Adicionar novo projeto...', | ||
click: () => { | ||
const result = dialog.showOpenDialog({ properties: ['openDirectory'] }); | ||
|
||
if (!result) return; | ||
|
||
const [path] = result; | ||
const name = basename(path); | ||
|
||
store.set('projects', JSON.stringify([...projects, { | ||
path, | ||
name, | ||
}])); | ||
|
||
render(); | ||
}, | ||
}, | ||
{ | ||
type: 'separator', | ||
}, | ||
...items, | ||
{ | ||
type: 'separator', | ||
}, | ||
{ | ||
type: 'normal', | ||
label: 'Fechar Code Tray', | ||
role: 'quit', | ||
enabled: true, | ||
}, | ||
]); | ||
|
||
tray.setToolTip('This is my application'); | ||
tray.setContextMenu(contextMenu); | ||
}); | ||
} | ||
|
||
app.on('ready', () => { | ||
const tray = new Tray(resolve(__dirname, 'assets', 'iconTemplate.png')); | ||
|
||
render(tray); | ||
}); |
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 |
---|---|---|
@@ -1,14 +1,42 @@ | ||
{ | ||
"name": "code-tray", | ||
"description": "Open VSCode projects from tray menu.", | ||
"version": "1.0.0", | ||
"main": "main.js", | ||
"repository": "https://github.com/diego3g/youtube-challenge-electron-tray", | ||
"author": "Diego Fernandes <diego.schell.f@gmail.com>", | ||
"author": "Rocketseat <oi@rocketseat.com.br>", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "electron ." | ||
"start": "electron .", | ||
"pack": "electron-builder --dir", | ||
"dist": "electron-builder", | ||
"postinstall": "electron-builder install-app-deps" | ||
}, | ||
"dependencies": { | ||
"electron": "^5.0.7" | ||
"@sentry/electron": "0.17.1", | ||
"cross-spawn": "^6.0.5", | ||
"electron-store": "^4.0.0", | ||
"fix-path": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"electron": "^5.0.7", | ||
"electron-builder": "^21.0.15", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb-base": "^13.2.0", | ||
"eslint-plugin-import": "^2.18.0" | ||
}, | ||
"build": { | ||
"appId": "com.rocketseat.codetray", | ||
"productName": "Code Tray", | ||
"mac": { | ||
"category": "public.app-category.developer-tools" | ||
}, | ||
"linux": { | ||
"category": "Utility", | ||
"icon": "iconLinux.png", | ||
"target": [ | ||
"AppImage" | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.