Skip to content

Commit

Permalink
Added the restore last tabs.
Browse files Browse the repository at this point in the history
Bump electron on 4.0.5
Fixed #28. Change the version of desktop app.
  • Loading branch information
ChugunovRoman committed Feb 15, 2019
1 parent 07bdea9 commit 8376afe
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 36 deletions.
7 changes: 6 additions & 1 deletion config/webpack.config.renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const rootFolder = process.cwd();
const render = {
entry: {
'../middleware/loadMainContetnt': path.resolve(rootFolder, 'src/middleware/loadMainContetnt.ts'),
'../middleware/loadContetnt': path.resolve(rootFolder, 'src/middleware/loadContetnt.ts')
'../middleware/loadContetnt': path.resolve(rootFolder, 'src/middleware/loadContetnt.ts'),
'../middleware/webApi': path.resolve(rootFolder, 'src/middleware/webApi.ts')
},

module: {
noParse: /webApi/
},

resolve: {
Expand Down
49 changes: 31 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^0.28.11",
"electron": "^3.1.0",
"electron": "^4.0.5",
"electron-builder": "^20.38.4",
"electron-rebuild": "^1.8.2",
"electron-webpack": "^2.6.1",
Expand Down
Binary file modified src/main/binding.node
Binary file not shown.
2 changes: 1 addition & 1 deletion src/middleware/ShortcutMan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface Sequence {
/**
* Singleton for register shortcuts in window
*/
class ShortcutMan {
export class ShortcutMan {
private static _instance: ShortcutMan;
private sequenceMap: Array<Sequence> = [];
private shiftMap: any = {
Expand Down
17 changes: 17 additions & 0 deletions src/middleware/shortcutBinding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default (shortcutsMap: ShortcutsMap[], shortcutMan: any) => {
console.log('shortcutsMap: ', typeof shortcutsMap);
for (let shortcut of shortcutsMap) {
if (shortcut.accelerator === '') continue;

switch (shortcut.type) {
case 'action': {
shortcutMan.bind(shortcut.accelerator.toLocaleLowerCase(), () => {
console.log('Action: ', shortcut);
if (shortcut.value === 'save-as') return;
});
} break;

default: {}
}
}
}
10 changes: 5 additions & 5 deletions src/middleware/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as E from "electron";
import * as Settings from "electron-settings";

import { shortcutsMap, handleCommandItemClick, handleItemAction } from "Utils";
import shortcutMan from "./ShortcutMan";

export default () => {
const currentWindow = E.remote.BrowserWindow.getAllWindows()[0];

// TODO: get from settings
let isMenuHidden: boolean = false;
let actionState: any = {};

E.remote.app.on('updateActionState', (state: any) => {
Expand All @@ -20,22 +19,23 @@ export default () => {
switch (shortcut.type) {
case 'action': {
shortcutMan.bind(shortcut.accelerator.toLocaleLowerCase(), () => {
if (!isMenuHidden) return;
console.log('Action: ', !Settings.get('app.disabledMainMenu'), shortcut);
if (!Settings.get('app.disabledMainMenu')) return;
if (shortcut.value === 'save-as') return;

actionState[shortcut.value] && handleItemAction({ action: shortcut.value, accelerator: shortcut.accelerator }, currentWindow);
});
} break;
case 'command': {
shortcutMan.bind(shortcut.accelerator.toLocaleLowerCase(), () => {
if (!isMenuHidden) return;
if (!Settings.get('app.disabledMainMenu')) return;

handleCommandItemClick({ command: shortcut.value, accelerator: shortcut.accelerator }, currentWindow);
});
} break;
case 'id': {
shortcutMan.bind(shortcut.accelerator.toLocaleLowerCase(), () => {
if (!isMenuHidden) return;
if (!Settings.get('app.disabledMainMenu')) return;

E.remote.app.emit('handleCommand', shortcut.value);
});
Expand Down
116 changes: 116 additions & 0 deletions src/middleware/webApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
interface IIntiApiOptions {
version: number;
fileBrowser: boolean;
shortcutBinding?: any;
shortcutsMap?: ShortcutsMap[];
shortcutMan?: any;
}

export default (args: IIntiApiOptions) => {
const channel = new MessageChannel();
const pendingPromises = new Map();
let messageHandler: Function;
let nextPromiseID = 0;
let messageQueue: Array<any> = [];

console.log('args: ', args, args.shortcutMan);
const shortcutBinding = new Function(`return ${args.shortcutBinding}`);
console.log('args.shortcutBinding: ', `return ${args.shortcutBinding}`);
console.log('shortcutBinding(args.shortcutsMap): ', shortcutBinding()(args.shortcutsMap, args.shortcutMan));

const tryFlushMessages = () => {
if (messageHandler) {
while (true) {
const msg = messageQueue.shift();
if (!msg) {
break;
}
messageHandler(msg.name, msg.args);
}
}
}

window.__figmaContent = false;

window.__figmaDesktop = {
version: args.version,
fileBrowser: args.fileBrowser,
postMessage: function (name, args, transferList) {
console.log('postMessage, name, args, transferList: ', name, args, transferList);
window.__figmaDesktop.fileBrowser = false;

// FIXME: ugly hack
if (!/recent/.test(window.location.href) && name === 'updateActionState') {
let state = {
'save-as': true,
'export-selected-exportables': true,
'toggle-grid': true,
'toggle-shown-layout-grids': true,
'toggle-show-masks': true,
'toggle-show-artboard-outlines': true,
'toggle-rulers': true,
'toggle-sidebar': true,
'toggle-ui': true,
'toggle-outlines': true,
'toggle-layers': true,
'toggle-publish': true,
'toggle-library': true,
'toggle-pixel-preview': true,
'toggle-checkerboard': true,
'zoom-in': true,
'zoom-out': true,
'zoom-reset': true,
'zoom-to-fit': true,
'zoom-to-selection': true,
'next-artboard': true,
'previous-artboard': true
};

channel.port1.postMessage({ name, args: { state: { ...args.state, ...state } } }, transferList);

return;
}

channel.port1.postMessage({ name, args }, transferList);

},
promiseMessage: function (name, args, transferList) {
console.log('promiseMessage, name, args, transferList: ', name, args, transferList);
return new Promise((resolve, reject) => {
const id = nextPromiseID++;
pendingPromises.set(id, { resolve, reject });
channel.port1.postMessage({ name, args, promiseID: id }, transferList);
});
},
setMessageHandler: function (handler) {
console.log('setMessageHandler: handler', handler);
messageHandler = handler;
tryFlushMessages();
},
};

channel.port1.onmessage = (event: MessageEvent) => {
const msg = event.data;

if (!msg) return;
console.log('channel.port1.onmessage, event: ', event);
if (msg.promiseID != null) {
const pendingPromise = pendingPromises.get(msg.promiseID);
if (pendingPromise) {
pendingPromises.delete(msg.promiseID);
if ('result' in msg) {
pendingPromise.resolve(msg.result);
}
else {
pendingPromise.reject(msg.error);
}
}
}
else if (msg.name != null) {
messageQueue.push(msg);
tryFlushMessages();
}
};

window.postMessage('init', location.origin, [channel.port2]);
}
Loading

0 comments on commit 8376afe

Please sign in to comment.