From 3bbf0cffa13c02cf8acbc99ec94ae22817b7bf99 Mon Sep 17 00:00:00 2001 From: t9md Date: Wed, 19 Apr 2017 17:58:48 +0900 Subject: [PATCH] Focus Atom application when text-synced from chrome browser --- lib/atomic-chrome.coffee | 8 +++----- lib/ws-handler.coffee | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/atomic-chrome.coffee b/lib/atomic-chrome.coffee index cb3873a..1115bf4 100644 --- a/lib/atomic-chrome.coffee +++ b/lib/atomic-chrome.coffee @@ -1,8 +1,5 @@ -{CompositeDisposable} = require 'atom' -{Server} = require 'ws' - -WSHandler = require './ws-handler' - +{Server} = require 'ws' +WSHandler = null # defer require till necessary WS_PORT = 64292 module.exports = AtomicChrome = @@ -10,6 +7,7 @@ module.exports = AtomicChrome = @wss = new Server({port: WS_PORT}) @wss.on 'connection', (ws) -> + WSHandler ?= require './ws-handler' new WSHandler(ws) @wss.on 'error', (err) -> console.error(err) unless err.code == 'EADDRINUSE' diff --git a/lib/ws-handler.coffee b/lib/ws-handler.coffee index 347465f..22bbd3d 100644 --- a/lib/ws-handler.coffee +++ b/lib/ws-handler.coffee @@ -13,6 +13,7 @@ module.exports = class WSHandler register: (data) -> filepath = @getFile(data) + atom.focus() # activivate Atom application atom.workspace.open(filepath).then (editor) => @initEditor(editor, data)