Skip to content

Commit

Permalink
refactor: remove timeout and add ready message to main thread
Browse files Browse the repository at this point in the history
menu removed, because it had no added value
  • Loading branch information
ph1p committed Jan 7, 2020
1 parent 3af854a commit 6a799d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
12 changes: 1 addition & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@
"id": "742073255743594050",
"api": "1.0.0",
"main": "code.js",
"ui": "ui.html",
"menu": [
{
"name": "Open Chat",
"command": "show"
},
{
"name": "Hide Chat",
"command": "hide"
}
]
"ui": "ui.html"
},
"dependencies": {
"prop-types": "^15.7.2",
Expand Down
10 changes: 3 additions & 7 deletions src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ const postMessage = (type = '', payload = {}) =>
payload
});

if (figma.command === 'hide') {
figma.ui.hide();
}

if (figma.command === 'show') {
figma.ui.show();
}
figma.ui.show();

main().then(({ roomName, secret, history, instanceId }) => {
postMessage('ready');

// events
figma.on('selectionchange', () => {
postMessage(
Expand Down
8 changes: 5 additions & 3 deletions src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import MinimizedView from './views/minimized';
import SettingsView from './views/settings';
import UserListView from './views/user-list';

// wait 100ms to initialize, to prevent race conditions
setTimeout(() => sendMainMessage('initialize'), 100);

onmessage = message => {
if (message.data.pluginMessage) {
const { type, payload } = message.data.pluginMessage;

// initialize
if (type === 'ready') {
sendMainMessage('initialize');
}

if (type === 'initialize') {
init(payload !== '' ? payload : DEFAULT_SERVER_URL);
}
Expand Down

0 comments on commit 6a799d9

Please sign in to comment.