通过Chrome扩展程序与MacOSX应用进行对话 [英] Talk to MacOSX app from Chrome Extension

查看:149
本文介绍了通过Chrome扩展程序与MacOSX应用进行对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的浏览器中正在运行一个Chrome扩展程序.我也有一个Mac OSX应用程序,是我用Xcode在Swift/Objective-c中编写的.我想知道这个Chrome扩展程序如何与同一台计算机上的Mac OSX应用程序通信.

I have a chrome extension running in my browser. I also have a Mac OSX app I wrote in Swift/Objective-c in Xcode. I am wondering how this chrome extension can talk to the Mac OSX app on the same computer.

我知道Chrome扩展程序API,但不知道如何捕获来自Chrome在Swift中发送的信息.有人知道该怎么做吗?

I am aware of the Chrome Extension API, but do not know how I can capture the information from that is sent by Chrome in Swift. Does anyone know how to do this?

谢谢

推荐答案

您可以采用两种广泛的方法.

There are two broad approaches you can take.

  1. 本地消息API .这确实有一个限制,即Chrome必须启动该进程(并通过STDIO与之通信)-您无法附加到现有进程.好处-沟通渠道非常安全.

  1. Native Messaging API. This does have the limitation that Chrome must launch the process (and communicate to it via STDIO) - you cannot attach to an existing process. The upside - the communication channel is pretty secure.

您的本机应用程序可以在本地端口上公开Web服务器(或者更好的是WebSockets服务器).然后,扩展程序可以尝试连接到此端口并与您的应用程序对话.缺点是任何东西(至少在计算机上)都可以连接到您的本机应用程序.

Your native app can expose a web server (or better yet, a WebSockets server) on a local port. The extension can then try to connect to this port and talk to your app. The downside is that anything (at least on the machine) can connect to your native app.

这是一种常用的方法;例如1Password或各种IDE集成就是这样.

This is a frequently used approach; for example, 1Password or various IDE integrations work this way.

您可以结合使用两种方法来通过启动器"启动应用程序.本机主机(如果未运行).

You could combine the two approaches to launch the app with a "launcher" Native Host if it's not running.

这篇关于通过Chrome扩展程序与MacOSX应用进行对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆