Skip to content

Commit 335f1f6

Browse files
committed
dev -> master
2 parents c56bd64 + 9715482 commit 335f1f6

4 files changed

Lines changed: 157 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "MIT",
99
"scripts": {
1010
"start": "electron src/main/index.js",
11-
"pack": "electron-packager ./ Figma-app --paltform=Linux --arch=x64 --executable-name=figma-linux --overwrite ./build",
11+
"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",
1212
"deb": "electron-installer-debian --src ./Figma-app-linux-x64 --dest ./build/installers --arch=amd64"
1313
},
1414
"dependencies": {

src/main/index.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const {
2+
shell,
3+
app,
4+
net,
5+
session,
6+
BrowserWindow,
7+
} = require('electron');
8+
const url = require('url');
9+
const shorcuts = require('./shortcuts');
10+
const menu = require('./menu');
11+
12+
const HOME = 'https://www.figma.com'
13+
const winOptions = {
14+
width: 1200,
15+
height: 900,
16+
frame: false,
17+
webPreferences: {
18+
nodeIntegration: false,
19+
'web-security': false,
20+
webgl: true,
21+
experimentalFeatures: true,
22+
experimentalCanvasFeatures: true,
23+
zoomFactor: 0.7
24+
}
25+
};
26+
27+
app.on('ready', () => {
28+
let window = new BrowserWindow(winOptions);
29+
30+
window.setMenuBarVisibility(false);
31+
window.loadURL(HOME);
32+
33+
window.webContents.on('will-navigate', (event, url) => {
34+
parts = url.split("/");
35+
if (parts[0] + "//" + parts[2] != HOME) {
36+
event.preventDefault()
37+
shell.openExternal(url)
38+
};
39+
});
40+
41+
shorcuts(window);
42+
menu(window);
43+
44+
45+
window.webContents.on('will-navigate', (event, newUrl) => {
46+
const currentUrl = event.sender.getURL();
47+
48+
if (newUrl === currentUrl) {
49+
window.reload();
50+
51+
event.preventDefault();
52+
return;
53+
}
54+
55+
const from = url.parse(currentUrl);
56+
const to = url.parse(newUrl);
57+
58+
if (from.pathname === '/login') {
59+
window.reload();
60+
return;
61+
}
62+
63+
if (to.pathname === '/logout') {
64+
net.request(`${HOME}/logout`).on('response', response => {
65+
response.on('data', chunk => {});
66+
response.on('error', err => {
67+
console.log('Request error: ', err);
68+
});
69+
response.on('end', () => {
70+
console.log('response.statusCode: ', response.statusCode);
71+
if (response.statusCode >= 200 && response.statusCode <= 299) {
72+
73+
session.defaultSession.cookies.flushStore(() => {
74+
const reload = () => app.relaunch({
75+
args: process.argv.slice(1).concat(['--reset'])
76+
});
77+
78+
app.on('will-quit', reload);
79+
app.quit();
80+
});
81+
}
82+
});
83+
}).end();;
84+
85+
event.preventDefault();
86+
return;
87+
}
88+
});
89+
90+
// window.webContents.on('did-navigate', (event) => {
91+
// console.log('did-navigate event args:', event.sender.getURL());
92+
// });
93+
94+
window.webContents.on('new-window', (...args) => {
95+
console.log('new-window event args:', args);
96+
});
97+
98+
window.on('closed', () => {
99+
window = null;
100+
});
101+
});
102+
103+
app.on('window-all-closed', () => {
104+
105+
if(process.platform !== 'darwin') {
106+
app.quit();
107+
}
108+
});

src/main/menu.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { Menu, MenuItem } = require('electron');
2+
3+
const menu = new Menu();
4+
5+
module.exports = (window) => {
6+
7+
menu.append(new MenuItem({
8+
label: 'Window',
9+
accelerator: 'F5',
10+
visible: false,
11+
click: () => {
12+
window.reload();
13+
}
14+
}));
15+
16+
menu.append(new MenuItem({
17+
label: 'DevTools',
18+
accelerator: 'ctrl+alt+i',
19+
visible: false,
20+
click: () => {
21+
window.webContents.openDevTools();
22+
}
23+
}));
24+
25+
Menu.setApplicationMenu(menu);
26+
}

src/main/shortcuts.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { globalShortcut } = require('electron');
2+
3+
module.exports = (window) => {
4+
let zoom = 0.7;
5+
6+
globalShortcut.register('CommandOrControl+-', () => {
7+
zoom -= 0.1;
8+
window.webContents.setZoomFactor(zoom);
9+
});
10+
globalShortcut.register('CommandOrControl+=', () => {
11+
zoom += 0.1;
12+
window.webContents.setZoomFactor(zoom);
13+
});
14+
globalShortcut.register('Shift+CommandOrControl+-', () => {
15+
zoom -= 0.05;
16+
window.webContents.setZoomFactor(zoom);
17+
});
18+
globalShortcut.register('Shift+CommandOrControl+=', () => {
19+
zoom += 0.05;
20+
window.webContents.setZoomFactor(zoom);
21+
});
22+
}

0 commit comments

Comments
 (0)