Skip to content

Commit

Permalink
dev -> master
Browse files Browse the repository at this point in the history
  • Loading branch information
ChugunovRoman committed Mar 20, 2018
2 parents c56bd64 + 9715482 commit 335f1f6
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"scripts": {
"start": "electron src/main/index.js",
"pack": "electron-packager ./ Figma-app --paltform=Linux --arch=x64 --executable-name=figma-linux --overwrite ./build",
"pack": "rm -rf Figma-app-linux-x64 && electron-packager ./ Figma-app --ignore=\"(\\.git|node_modules|build|\\.bak|config|\\.log|yarn)\" --paltform=Linux --arch=x64 --executable-name=figma-linux --overwrite ./build",
"deb": "electron-installer-debian --src ./Figma-app-linux-x64 --dest ./build/installers --arch=amd64"
},
"dependencies": {
Expand Down
108 changes: 108 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const {
shell,
app,
net,
session,
BrowserWindow,
} = require('electron');
const url = require('url');
const shorcuts = require('./shortcuts');
const menu = require('./menu');

const HOME = 'https://www.figma.com'
const winOptions = {
width: 1200,
height: 900,
frame: false,
webPreferences: {
nodeIntegration: false,
'web-security': false,
webgl: true,
experimentalFeatures: true,
experimentalCanvasFeatures: true,
zoomFactor: 0.7
}
};

app.on('ready', () => {
let window = new BrowserWindow(winOptions);

window.setMenuBarVisibility(false);
window.loadURL(HOME);

window.webContents.on('will-navigate', (event, url) => {
parts = url.split("/");
if (parts[0] + "//" + parts[2] != HOME) {
event.preventDefault()
shell.openExternal(url)
};
});

shorcuts(window);
menu(window);


window.webContents.on('will-navigate', (event, newUrl) => {
const currentUrl = event.sender.getURL();

if (newUrl === currentUrl) {
window.reload();

event.preventDefault();
return;
}

const from = url.parse(currentUrl);
const to = url.parse(newUrl);

if (from.pathname === '/login') {
window.reload();
return;
}

if (to.pathname === '/logout') {
net.request(`${HOME}/logout`).on('response', response => {
response.on('data', chunk => {});
response.on('error', err => {
console.log('Request error: ', err);
});
response.on('end', () => {
console.log('response.statusCode: ', response.statusCode);
if (response.statusCode >= 200 && response.statusCode <= 299) {

session.defaultSession.cookies.flushStore(() => {
const reload = () => app.relaunch({
args: process.argv.slice(1).concat(['--reset'])
});

app.on('will-quit', reload);
app.quit();
});
}
});
}).end();;

event.preventDefault();
return;
}
});

// window.webContents.on('did-navigate', (event) => {
// console.log('did-navigate event args:', event.sender.getURL());
// });

window.webContents.on('new-window', (...args) => {
console.log('new-window event args:', args);
});

window.on('closed', () => {
window = null;
});
});

app.on('window-all-closed', () => {

if(process.platform !== 'darwin') {
app.quit();
}
});
26 changes: 26 additions & 0 deletions src/main/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { Menu, MenuItem } = require('electron');

const menu = new Menu();

module.exports = (window) => {

menu.append(new MenuItem({
label: 'Window',
accelerator: 'F5',
visible: false,
click: () => {
window.reload();
}
}));

menu.append(new MenuItem({
label: 'DevTools',
accelerator: 'ctrl+alt+i',
visible: false,
click: () => {
window.webContents.openDevTools();
}
}));

Menu.setApplicationMenu(menu);
}
22 changes: 22 additions & 0 deletions src/main/shortcuts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { globalShortcut } = require('electron');

module.exports = (window) => {
let zoom = 0.7;

globalShortcut.register('CommandOrControl+-', () => {
zoom -= 0.1;
window.webContents.setZoomFactor(zoom);
});
globalShortcut.register('CommandOrControl+=', () => {
zoom += 0.1;
window.webContents.setZoomFactor(zoom);
});
globalShortcut.register('Shift+CommandOrControl+-', () => {
zoom -= 0.05;
window.webContents.setZoomFactor(zoom);
});
globalShortcut.register('Shift+CommandOrControl+=', () => {
zoom += 0.05;
window.webContents.setZoomFactor(zoom);
});
}

0 comments on commit 335f1f6

Please sign in to comment.