Skip to content

Commit 3e381f0

Browse files
committed
Support newer plugin API
Support plugin API introduced in version 5.2.2 of Textual
1 parent 543ae2f commit 3e381f0

File tree

4 files changed

+63
-56
lines changed

4 files changed

+63
-56
lines changed

Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
<key>CFBundleExecutable</key>
88
<string>${EXECUTABLE_NAME}</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.example.extension.SwiftPluginExample</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleName</key>
1212
<string>${PRODUCT_NAME}</string>
1313
<key>CFBundlePackageType</key>
1414
<string>BNDL</string>
1515
<key>CFBundleVersion</key>
1616
<string>1.0.0</string>
17-
<key>NSPrincipalClass</key>
18-
<string>TPI_SwiftPluginExample</string>
1917
<key>MinimumTextualVersion</key>
2018
<string>5.0.0</string>
19+
<key>NSPrincipalClass</key>
20+
<string>TPI_SwiftPluginExample</string>
2121
</dict>
2222
</plist>

SwiftPluginExample.swift

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,93 +6,95 @@ import Foundation
66
loads, it must inherit NSObject to allow proper initialization. */
77
/* THOPluginProtocol is the protocol available for plugin specific callbacks.
88
It is appended to our new class object to inform Swift that we conform to it. */
9+
910
class TPI_SwiftPluginExample: NSObject, THOPluginProtocol
1011
{
11-
func subscribedServerInputCommands() -> [AnyObject]!
12-
{
13-
/* Accept all incoming server data corresponding to the
14-
commands PRIVMSG and NOTICE. The plugin will perform
15-
different actions for each value. */
16-
17-
return ["privmsg", "notice"]
12+
var subscribedServerInputCommands: [AnyObject]! {
13+
get {
14+
return ["privmsg", "notice"]
15+
}
1816
}
19-
20-
func didReceiveServerInputOnClient(client: IRCClient!, senderInformation senderDict: [NSObject : AnyObject]!, messageInformation messageDict: [NSObject : AnyObject]!)
17+
18+
func didReceiveServerInput(inputObject: THOPluginDidReceiveServerInputConcreteObject!, onClient client: IRCClient!)
2119
{
2220
/* Swift provides a very powerful switch statement so
2321
it is easier to use that for identifying commands than
2422
using an if statement if more than the two are added. */
25-
let commandValue = (messageDict[THOPluginProtocolDidReceiveServerInputMessageCommandAttribute] as String)
2623

27-
switch (commandValue) {
24+
NSLog("%@ %@", inputObject.messageCommand, inputObject.messageParamaters)
25+
26+
switch (inputObject.messageCommand) {
2827
case "PRIVMSG":
29-
self.handleIncomingPrivateMessageCommand(client, senderDict: senderDict, messageDict: messageDict)
28+
self.handleIncomingPrivateMessageCommand(inputObject, onClient: client)
3029
case "NOTICE":
31-
self.handleIncomingNoticeCommand(client, senderDict: senderDict, messageDict: messageDict)
30+
self.handleIncomingNoticeCommand(inputObject, onClient: client)
3231
default:
33-
return;
32+
return
3433
}
3534
}
36-
37-
func handleIncomingPrivateMessageCommand(client: IRCClient!, senderDict: [NSObject : AnyObject]!, messageDict: [NSObject : AnyObject]!)
35+
36+
func handleIncomingPrivateMessageCommand(inputObject: THOPluginDidReceiveServerInputConcreteObject!, onClient client: IRCClient!)
3837
{
3938
/* Get message sequence of incoming message. */
40-
let messageReceived = (messageDict[THOPluginProtocolDidReceiveServerInputMessageSequenceAttribute] as String)
41-
42-
let messageParamaters = (messageDict[THOPluginProtocolDidReceiveServerInputMessageParamatersAttribute] as Array<String>)
43-
39+
let messageReceived = (inputObject.messageSequence as String)
40+
41+
let messageParamaters = (inputObject.messageParamaters as! Array<String>)
42+
4443
/* Get channel that message was sent from. */
4544
/* The first paramater of the PRIVMSG command is always
4645
the channel the message was targetted to. */
4746
let senderChannel = client.findChannel(messageParamaters[0])
48-
47+
4948
/* Do not accept private messages. */
5049
if senderChannel.isPrivateMessage {
51-
return;
50+
return
5251
}
53-
52+
5453
/* Get sender of message. */
55-
let messageSender = (senderDict[THOPluginProtocolDidReceiveServerInputSenderNicknameAttribute] as String)
56-
54+
let messageSender = (inputObject.senderNickname as String)
55+
5756
/* Ignore this user, he's kind of a jerk. :-( */
5857
if messageSender.hasPrefix("Alex") {
59-
return;
58+
return
6059
}
61-
60+
6261
/* Compare it against a specific value. */
6362
if (messageReceived == "do you know what time it is?" ||
6463
messageReceived == "does anybody know what time it is?")
6564
{
6665
/* Format message. */
67-
let formattedString = (messageSender + " the time where I am is: " + self.formattedDateTimeString());
68-
66+
let formattedString = (messageSender + ", the time where I am is: " + self.formattedDateTimeString())
67+
6968
/* Invoke the client on the main thread when sending. */
7069
self.performBlockOnMainThread({
7170
client.sendPrivmsg(formattedString, toChannel: senderChannel)
72-
});
71+
})
7372
}
7473
}
75-
76-
func handleIncomingNoticeCommand(client: IRCClient!, senderDict: [NSObject : AnyObject]!, messageDict: [NSObject : AnyObject]!)
74+
75+
func handleIncomingNoticeCommand(inputObject: THOPluginDidReceiveServerInputConcreteObject!, onClient client: IRCClient!)
7776
{
7877
// Not implemented.
7978
}
80-
79+
8180
/* Support a new command in text field. */
82-
func subscribedUserInputCommands() -> [AnyObject]!
83-
{
84-
return ["datetime"]
81+
var subscribedUserInputCommands: [AnyObject]! {
82+
get {
83+
return ["datetime"]
84+
}
8585
}
8686

8787
func userInputCommandInvokedOnClient(client: IRCClient!, commandString: String!, messageString: String!)
8888
{
89-
let formattedString = ("The current time is: " + self.formattedDateTimeString());
89+
let formattedString = ("The current time is: " + self.formattedDateTimeString())
90+
91+
let mainWindow = self.masterController().mainWindow;
9092

9193
self.performBlockOnMainThread({
92-
client.sendPrivmsg(formattedString, toChannel:self.masterController().mainWindow.selectedChannel)
93-
});
94+
client.sendPrivmsg(formattedString, toChannel:mainWindow.selectedChannel)
95+
})
9496
}
95-
97+
9698
/* Helper functions. */
9799
func formattedDateTimeString() -> (String)
98100
{

SwiftPluginExample.xcodeproj/project.pbxproj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
089C1669FE841209C02AAC07 /* Project object */ = {
115115
isa = PBXProject;
116116
attributes = {
117-
LastUpgradeCheck = 0600;
117+
LastSwiftUpdateCheck = 0700;
118+
LastUpgradeCheck = 0700;
118119
};
119120
buildConfigurationList = 1DEB911E08733D790010E9CD /* Build configuration list for PBXProject "SwiftPluginExample" */;
120121
compatibilityVersion = "Xcode 3.2";
@@ -161,13 +162,14 @@
161162
1DEB911B08733D790010E9CD /* Debug */ = {
162163
isa = XCBuildConfiguration;
163164
buildSettings = {
164-
BUNDLE_LOADER = "/Applications/Textual 5.app/Contents/MacOS/Textual 5";
165+
BUNDLE_LOADER = /Applications/Textual.app/Contents/MacOS/Textual;
165166
COMBINE_HIDPI_IMAGES = YES;
166167
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
167-
FRAMEWORK_SEARCH_PATHS = "\"/Applications/Textual 5.app/Contents/Frameworks/**\"";
168-
HEADER_SEARCH_PATHS = "\"/Applications/Textual 5.app/Contents/Headers/**\"";
168+
FRAMEWORK_SEARCH_PATHS = "\"/Applications/Textual.app/Contents/Frameworks/**\"";
169+
HEADER_SEARCH_PATHS = "\"/Applications/Textual.app/Contents/Headers/**\"";
169170
INFOPLIST_FILE = Info.plist;
170171
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
172+
PRODUCT_BUNDLE_IDENTIFIER = com.example.extension.SwiftPluginExample;
171173
PRODUCT_NAME = SwiftPluginExample;
172174
SWIFT_OBJC_BRIDGING_HEADER = "SwiftPluginExample-Bridging-Header.h";
173175
WRAPPER_EXTENSION = bundle;
@@ -177,13 +179,14 @@
177179
1DEB911C08733D790010E9CD /* Release */ = {
178180
isa = XCBuildConfiguration;
179181
buildSettings = {
180-
BUNDLE_LOADER = "/Applications/Textual 5.app/Contents/MacOS/Textual 5";
182+
BUNDLE_LOADER = /Applications/Textual.app/Contents/MacOS/Textual;
181183
COMBINE_HIDPI_IMAGES = YES;
182184
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
183-
FRAMEWORK_SEARCH_PATHS = "\"/Applications/Textual 5.app/Contents/Frameworks/**\"";
184-
HEADER_SEARCH_PATHS = "\"/Applications/Textual 5.app/Contents/Headers/**\"";
185+
FRAMEWORK_SEARCH_PATHS = "\"/Applications/Textual.app/Contents/Frameworks/**\"";
186+
HEADER_SEARCH_PATHS = "\"/Applications/Textual.app/Contents/Headers/**\"";
185187
INFOPLIST_FILE = Info.plist;
186188
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
189+
PRODUCT_BUNDLE_IDENTIFIER = com.example.extension.SwiftPluginExample;
187190
PRODUCT_NAME = SwiftPluginExample;
188191
SWIFT_OBJC_BRIDGING_HEADER = "SwiftPluginExample-Bridging-Header.h";
189192
WRAPPER_EXTENSION = bundle;
@@ -193,7 +196,6 @@
193196
1DEB911F08733D790010E9CD /* Debug */ = {
194197
isa = XCBuildConfiguration;
195198
buildSettings = {
196-
COPY_PHASE_STRIP = NO;
197199
GCC_OPTIMIZATION_LEVEL = 0;
198200
ONLY_ACTIVE_ARCH = YES;
199201
};

SwiftPluginExample.xcodeproj/xcshareddata/xcschemes/SwiftPluginExample.xcscheme

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0600"
3+
LastUpgradeVersion = "0700"
44
version = "2.0">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -23,22 +23,25 @@
2323
</BuildActionEntries>
2424
</BuildAction>
2525
<TestAction
26+
buildConfiguration = "Release"
2627
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2728
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28-
shouldUseLaunchSchemeArgsEnv = "YES"
29-
buildConfiguration = "Release">
29+
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
3131
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
3234
</TestAction>
3335
<LaunchAction
36+
buildConfiguration = "Release"
3437
selectedDebuggerIdentifier = ""
3538
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
3639
launchStyle = "0"
3740
useCustomWorkingDirectory = "NO"
38-
buildConfiguration = "Release"
3941
ignoresPersistentStateOnLaunch = "NO"
4042
debugDocumentVersioning = "YES"
4143
debugXPCServices = "NO"
44+
debugServiceExtension = "internal"
4245
allowLocationSimulation = "YES">
4346
<MacroExpansion>
4447
<BuildableReference
@@ -53,10 +56,10 @@
5356
</AdditionalOptions>
5457
</LaunchAction>
5558
<ProfileAction
59+
buildConfiguration = "Release"
5660
shouldUseLaunchSchemeArgsEnv = "YES"
5761
savedToolIdentifier = ""
5862
useCustomWorkingDirectory = "NO"
59-
buildConfiguration = "Release"
6063
debugDocumentVersioning = "YES">
6164
</ProfileAction>
6265
<AnalyzeAction

0 commit comments

Comments
 (0)