How to embed a mac app extension in an Electron app?

本小妞迷上赌 提交于 2019-12-06 02:21:50

问题


I'm trying to embed a Finder Sync extension written in Swift in my app written with Electron. How can I manage to make them work together and communicate with each other? I have read the Apple documentation but it only explains how to add a target to a native application. I also noticed that I can manually inject the .appex compiled file (produced by XCode) in the application Plugins folder using electron builder. How can I develop and test the extension in XCode and embed it correctly in a custom Electron app? Any suggestion?

Thank you very much for any suggestion


回答1:


Create PlugIns folder in your Electron root folder.

Copy the .appex file into PlugIns folder.

If you are using electron-builder, modify the package.json file - add: "extraFiles": ["PlugIns/"] in the "mac" section.

Build. The Contents of your app package will contain the PlugIns folder and your appex file inside, and the appex will get loaded into your app's process.




回答2:


How to embed a mac app extension in an Electron app?

I would compile it as an independent binary and include it in some dir to be executed from the electron app using child_process.execFile

You can use arguments when executing the binary with execFile, here is an example (using promise)

const util = require('util');
const execFile = util.promisify(require('child_process').execFile);
async function FinderSyncExtPlugin(ARGUMENTS) {
  const { stdout } = await execFile('YourBinary', ARGUMENTS);
  console.log(stdout);
}
FinderSyncExtPlugin(['argument1','argument2','...']);

You could then use the stdout to know the status/result of the requested operation.



来源:https://stackoverflow.com/questions/45612515/how-to-embed-a-mac-app-extension-in-an-electron-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!