mac: Add support for Growl notifications

This commit is contained in:
Hylke Bons 2011-05-29 23:22:12 +01:00
parent e2d75a57fb
commit 09fc1bc4cf
4 changed files with 120 additions and 7 deletions

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>TicketVersion</key>
<integer>1</integer>
<key>AllNotifications</key>
<array>
<string>Start</string>
<string>Stop</string>
<string>Info</string>
</array>
<key>DefaultNotifications</key>
<array>
<string>Start</string>
<string>Stop</string>
<string>Info</string>
</array>
</dict>
</plist>

View file

@ -0,0 +1,58 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.Growl;
namespace SparkleShare {
public class SparkleBubble : NSObject {
public string ImagePath;
private string title;
private string subtext;
public SparkleBubble (string title, string subtext)
{
this.title = title;
this.subtext = subtext;
}
public void Show ()
{
InvokeOnMainThread (delegate {
if (ImagePath != null && File.Exists (ImagePath)) {
NSData image_data = NSData.FromFile (ImagePath);
GrowlApplicationBridge.Notify (this.title, this.subtext,
"Start", image_data, 0, false, null);
} else {
GrowlApplicationBridge.Notify (this.title, this.subtext,
"Start", null, 0, false, null);
}
});
}
}
}

View file

@ -22,6 +22,11 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CustomCommands>
<CustomCommands>
<Command type="AfterBuild" command="mkdir -p ${TargetDir}/${SolutionName}.app/Contents/Frameworks; cp -r /Users/hbons/Code/SparkleShare/SparkleShare/Mac/Growl.framework ${TargetDir}/${SolutionName}.app/Contents/Frameworks" externalConsole="true" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -83,6 +88,7 @@
</Compile>
<Compile Include="SparkleAbout.cs" />
<Compile Include="SparkleAlert.cs" />
<Compile Include="SparkleBubble.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />
@ -144,6 +150,7 @@
<Content Include="..\..\data\icons\idle4.png">
<Link>Pixmaps\idle4.png</Link>
</Content>
<Content Include="Growl.plist" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pixmaps\" />

View file

@ -24,7 +24,7 @@ using System.Timers;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
using MonoMac.Growl;
namespace SparkleShare {
@ -60,11 +60,22 @@ namespace SparkleShare {
public SparkleUI ()
{
NSApplication.Init ();
string content_path = Directory.GetParent (
System.AppDomain.CurrentDomain.BaseDirectory).ToString ();
string app_path = Directory.GetParent (content_path).ToString ();
string growl_path = Path.Combine (app_path, "Frameworks", "Growl.framework", "Growl");
// Needed for Growl
Dlfcn.dlopen (growl_path, 0);
NSApplication.Init ();
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
// Needed for Growl
GrowlApplicationBridge.WeakDelegate = this;
SetSparkleIcon ();
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
SetSparkleIcon ();
// TODO: Getting crashes when I remove this
NSApplication.SharedApplication.ApplicationIconImage
= NSImage.ImageNamed ("sparkleshare.icns");
@ -97,8 +108,17 @@ namespace SparkleShare {
NSApplication.SharedApplication.DockTile.BadgeLabel =
(int.Parse (NSApplication.SharedApplication.DockTile.BadgeLabel) + 1).ToString ();
NSApplication.SharedApplication.RequestUserAttention
(NSRequestUserAttentionType.InformationalRequest);
if (GrowlApplicationBridge.IsGrowlRunning ()) {
SparkleBubble bubble = new SparkleBubble (user_name, message) {
ImagePath = SparkleShare.Controller.GetAvatar (user_email, 36)
};
bubble.Show ();
} else {
NSApplication.SharedApplication.RequestUserAttention
(NSRequestUserAttentionType.InformationalRequest);
}
}
});
};
@ -143,5 +163,13 @@ namespace SparkleShare {
{
NSApplication.Main (new string [0]);
}
[Export("registrationDictionaryForGrowl")]
NSDictionary RegistrationDictionaryForGrowl ()
{
string path = NSBundle.MainBundle.PathForResource ("Growl", "plist");
return NSDictionary.FromFile (path);
}
}
}