Closed Bug 262037 (czpluginapi) Opened 21 years ago Closed 21 years ago

we need a better plugin API

Categories

(Other Applications Graveyard :: ChatZilla, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: samuel, Assigned: samuel)

References

Details

Attachments

(5 files, 2 obsolete files)

First draft: ChatZilla provides "PluginAPI" containing the version number in the plugin's scope. The plugin on loading must set a variable named "API" in the scope containing the version number that it provides. API version 1: plugin must provide the following functions: initPlugin: does any initialization the plugin needs, but does not enable it. enablePlugin: does whatever is required to activate the plugin. returns a boolean indicating whether or not the plugin was successfully enabled. disablePlugin: does whatever is required to deactivate the plugin. returns a boolean indicating whether or not the plugin was successfully disabled. ChatZilla will provide the following capabilities: on the first load of the plugin, it will attempt to enable the plugin. it will remember the state of the plugin, and on following loads, it will enable the plugin only if it was enabled the last time ChatZilla was closed. enablePlugin will not be called if the plugin is already enabled. disablePlugin will not be called if the plugin is already disabled.
I want to suggest that the variable containing the API version be plugin.API rather than plugin.scope.API. We already have variables, plugin.id, plugin.description, plugin.version, &c. In other words, this new variable should be in the same scope as the id, description, and version, rather than the variable-space of the plugin itself.
The reason these functions were in the global scope the first time around, is that I assumed it would be easier for the unwashed masses to understand. I'm not really tied to that though. Moving them to the plugin object could be a good way to distinguish old/new style plugins.
Draft 2: Remove the requirement for the API variable. Instead, the functions must be put on the plugin object. initPlugin -> plugin.init enablePlugin -> plugin.enable disablePlugin -> plugin.disable This will enable chatzilla to determine if it's a new plugin or an old plugin.
Update: plugin.id must be set to a unique name for the plugin. The only valid characters for the id are A-Z a-z 0-9 and _. The plugin's prefs will be found at extensions.irc.plugins.<id> in the pref tree. ChatZilla will set plugin.prefs and plugin.prefManager to be the prefs branch and pref manager for the plugin.
Oops, "-" is also valid in the id.
More details on prefs: An inital prefs array will be created before calling init() and stored in plugin.prefary. The init() function can add any more it needs to that array and the prefManager will be created after init() returns. If there is a function called plugin.onPrefChanged, then it will be set as the pref observer. If anyone can come up with a reason why init() will need to be accessing prefs instead of in enable(), then let me know because we couldn't come up with a scenario where that would be necessary.
One more thing to add since I'm sure it will be a FAQ if it's not included. plugin.cwd will contain the url to the plugin's working directory.
Attached patch new APISplinter Review
Comment on attachment 162317 [details] [diff] [review] new API The "networks." part of the pref branch shouldn't be there and has been removed locally.
Attachment #162317 - Flags: review?(rginda)
Comment on attachment 162317 [details] [diff] [review] new API r=rginda
Attachment #162317 - Flags: review?(rginda) → review+
The |id| is still being passed in... perhaps that could be changed to |url| or dropped entirely?
Attached patch update take 2Splinter Review
Attachment #163164 - Attachment is obsolete: true
Attachment #163178 - Flags: review?(rginda)
Blocks: 265453
Comment on attachment 163178 [details] [diff] [review] update take 2 How about dong the index assignment in the var declaration, instead of the if () clause? r=rginda with that change
Attachment #163178 - Flags: review?(rginda) → review+
this is mostly known, but just to have it written down: /disable-plugin and /enable plugin both give errors due to attempts to set a preference on old-style plugins when no preferences exist (enabled=false is the pref)
Attached file Example plugin using the new api. (obsolete) —
Not very useful, but shows how to use prefs, proper enable() and disable(), etc.
Attachment #165063 - Flags: review+
Comment on attachment 165063 [details] [diff] [review] fix enable/disable issues with oldstyle plugins Checked in.
Depends on: 269633
Product: Core → Other Applications
I believe everything from this bug is now FIXED.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Attachment #163871 - Attachment is obsolete: true
Alias: czpluginapi
please allow ALEXA tOOLBAR
Product: Other Applications → Other Applications Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: