Skip to content

Commit

Permalink
Cria versão 1.0 do Code Tray
Browse files Browse the repository at this point in the history
  • Loading branch information
diego3g committed Jul 16, 2019
1 parent 5ad9d27 commit db9241a
Show file tree
Hide file tree
Showing 8 changed files with 2,382 additions and 36 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.js
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: {
},
};
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules
dist
*.tgz
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
Binary file added build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/iconLinux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 87 additions & 8 deletions main.js
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);
});
34 changes: 31 additions & 3 deletions package.json
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"
]
}
}
}
Loading

0 comments on commit db9241a

Please sign in to comment.