{"id":22119547,"url":"https://github.com/zonble/zbsimplepluginmanager","last_synced_at":"2025-07-25T12:32:48.658Z","repository":{"id":56930350,"uuid":"118002836","full_name":"zonble/ZBSimplePluginManager","owner":"zonble","description":"A simple plug-in system by using JavaScriptCore.","archived":false,"fork":false,"pushed_at":"2019-10-15T04:10:06.000Z","size":180,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-30T21:42:27.876Z","etag":null,"topics":["ios","mac","swift"],"latest_commit_sha":null,"homepage":"https://github.com/zonble/ZBSimplePluginManager","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zonble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-18T15:44:16.000Z","updated_at":"2024-01-06T14:18:49.000Z","dependencies_parsed_at":"2022-08-21T05:50:20.449Z","dependency_job_id":null,"html_url":"https://github.com/zonble/ZBSimplePluginManager","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FZBSimplePluginManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FZBSimplePluginManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FZBSimplePluginManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FZBSimplePluginManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zonble","download_url":"https://codeload.github.com/zonble/ZBSimplePluginManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227574219,"owners_count":17788147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","mac","swift"],"created_at":"2024-12-01T14:15:09.309Z","updated_at":"2024-12-01T14:15:10.157Z","avatar_url":"https://github.com/zonble.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZBSimplePluginManager\n\nA simple plug-in system by using JavaScriptCore.\n\n[![Support](https://img.shields.io/badge/macOS-10.10-blue.svg)](https://www.apple.com/tw/macos)\u0026nbsp;\n[![Support](https://img.shields.io/badge/iOS-8-blue.svg)](https://www.apple.com/tw/ios)\u0026nbsp;\n[![Support](https://img.shields.io/badge/tvOS-9-blue.svg)](https://www.apple.com/tw/tvos)\u0026nbsp;\n\nCopyright (c) 2018 Weizhong Yang a.k.a zonble\n\n## Introduction\n\nA plug-in system helps to make your app more flexible.\n\nUsers may not need all of the functions in your app, and you may want to update the implementation of a function anytime. If you make these functions as plug-ins, users can enable or disable them when they need them or not, and you can let users to download new plug-ins if you hope so.\n\nApple introduced JavaScriptCore framework, a JavaScript interpreter, in iOS 7. It is a great tool and we could leverage it to build a simple plug-in system in your app easily. It is also quite easy to write new plug-ins, since they are just simple JavaScript code.\n\n## Requirement\n\nZBSimplePluginManager runs on iOS, macOS and tvOS.\n\n* Swift 4\n* iOS 8 or above.\n* macOS 10.10 or above.\n* tvOS 9 or above.\n\n## Installation\n\nThe SDK supports CocoaPods. Please add pod 'ZBSimplePluginManager' to your Podfile, and then call pod install.\n\n## Usage\n\nPlease create an instance of *ZBSimplePluginManager* by giving the folder where your plug-in files are, and a namespace for storing plug-in settings. A namespace here is a key that is used in NSUserDefaults to manage how a plug-in is enabled or disabled.\n\nThen, ask the manager to load all of the plug-ins in th given folder.\n\n``` swift\nlet resourceURL = URL(fileURLWithPath: Bundle.main.resourcePath!)\nlet pluginFolder = resourceURL.appendingPathComponent(\"PluginScripts\")\nlet pluginManager = ZBSimplePluginManager(pluginFolderURL: pluginFolder, defaultsNameSpace: \"plugins\")\npluginManager?.loadAllPlugins()\n```\n\nOnce the plug-ins are loaded, you can obtain a list of plug-ins from the manager.\n\n``` swift\nlet plugins = pluginManager.plugins\n```\n\nA plug-in that we defined in *ZBSimplePluginManager* has an identifier, a name and an action. You can call the action of a plug-in by passing specific parameters.\n\n```\nlet plugins = pluginManager.plugins\nLet plugin = plugins[0]\n_ = plugin.call(args: [\"Hello World!\"])\n```\n\n## Plug-in Files\n\nA plug-in may looks like:\n\n``` js\nvar youtubePlugin = {\n  id: 'plugin.google.search',\n  title: 'Search in Google...',\n  action: function (keyword) {\n    var url = 'https://google.com/search?q=' + encodeURIComponent(keyword)\n    openURL(url)\n  }\n}\n\nregisterPlugin(youtubePlugin)\n```\n\nWhat the plug-in does is:\n\n* Creating a JavaScript object with attributes including id, title, and action.\n* Call `registerPlugin` by passing the object to register it.\n\nIf there is already a plug-in registered with the same ID, you cannot register the plug-in.\n\n## JavaScript APIs\n\n*ZBSimplePluginManager* has only a few APIs that you can call from your JavaScript code right now, but it is also easy to extend the APIs.\n\n* `registerPlugin`: Register a new plug-in.\n* `log`: Print debug messages.\n* `openURL`: Open a given URL.\n\n*ZBSimplePluginManager* also provides a simple shared key/value storage in memory. You can use following functions to access it.\n\n* `set`: Set a value to the shared storage by giving a key.\n* `get`: Get a value by giving a key.\n\nYou can add your own functions to be called by your JavaScript code by simply calling `addJavaScriptAPI(functionName:, block:)`. For example, if you want to replace the existing `log` function, you can do this in your code:\n\n``` swift\ntry? self.addJavaScriptAPI(functionName: \"log\") { log in\n  if let log = log as? String {\n    print(\"[My Log]\" + log)\n  }\n  return nil\n}\n```\n\nThe body of your custom function is a Swift closure that has a simple input value and returns a value. Type of both of input and output value is optional any (written in \"Any?\"). You can cast the value by your self to satisfy your needs. By the way, you cannot replace the 'registerPlugin' function, otherwise we cannot register plug-ins.\n\nEnjoy!\n\n## License\n\n **LFLiveKit is released under the MIT license. See\n [LICENSE](https://github.com/zonble/ZBSimplePluginManager/blob/master/LICENSE) for details.**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzonble%2Fzbsimplepluginmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzonble%2Fzbsimplepluginmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzonble%2Fzbsimplepluginmanager/lists"}