mac statusicon: preload all images in memory so we don't get exceptions trying to find them
This commit is contained in:
parent
46d8eecb51
commit
b8646a8423
|
@ -46,7 +46,14 @@ namespace SparkleShare {
|
||||||
private NSMenuItem AboutMenuItem;
|
private NSMenuItem AboutMenuItem;
|
||||||
private NSMenuItem NotificationsMenuItem;
|
private NSMenuItem NotificationsMenuItem;
|
||||||
private NSMenuItem RecentEventsMenuItem;
|
private NSMenuItem RecentEventsMenuItem;
|
||||||
|
private NSImage [] AnimationFrames;
|
||||||
|
private NSImage [] AnimationFramesActive;
|
||||||
|
private NSImage ErrorImage;
|
||||||
|
private NSImage ErrorImageActive;
|
||||||
|
private NSImage FolderImage;
|
||||||
|
private NSImage CautionImage;
|
||||||
|
private NSImage SparkleShareImage;
|
||||||
|
|
||||||
private delegate void Task ();
|
private delegate void Task ();
|
||||||
private EventHandler [] Tasks;
|
private EventHandler [] Tasks;
|
||||||
|
|
||||||
|
@ -60,7 +67,14 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public SparkleStatusIcon () : base ()
|
public SparkleStatusIcon () : base ()
|
||||||
{
|
{
|
||||||
using (var a = new NSAutoreleasePool ()) {
|
using (var a = new NSAutoreleasePool ())
|
||||||
|
{
|
||||||
|
ErrorImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/error.png");
|
||||||
|
ErrorImageActive = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/error-active.png");
|
||||||
|
FolderImage = NSImage.ImageNamed ("NSFolder");
|
||||||
|
CautionImage = NSImage.ImageNamed ("NSCaution");
|
||||||
|
SparkleShareImage = NSImage.ImageNamed ("sparkleshare-mac");
|
||||||
|
|
||||||
Animation = CreateAnimation ();
|
Animation = CreateAnimation ();
|
||||||
|
|
||||||
StatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (28);
|
StatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (28);
|
||||||
|
@ -109,13 +123,12 @@ namespace SparkleShare {
|
||||||
StateText = _("Not everything is synced");
|
StateText = _("Not everything is synced");
|
||||||
StateMenuItem.Title = StateText;
|
StateMenuItem.Title = StateText;
|
||||||
CreateMenu ();
|
CreateMenu ();
|
||||||
|
|
||||||
InvokeOnMainThread (delegate {
|
StatusItem.Image = ErrorImage;
|
||||||
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/error.png");
|
StatusItem.AlternateImage = ErrorImageActive;
|
||||||
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/error-active.png");
|
StatusItem.Image.Size = new SizeF (16, 16);
|
||||||
StatusItem.Image.Size = new SizeF (16, 16);
|
StatusItem.AlternateImage.Size = new SizeF (16, 16);
|
||||||
StatusItem.AlternateImage.Size = new SizeF (16, 16);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,9 +139,10 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public void CreateMenu ()
|
public void CreateMenu ()
|
||||||
{
|
{
|
||||||
using (NSAutoreleasePool a = new NSAutoreleasePool ()) {
|
using (NSAutoreleasePool a = new NSAutoreleasePool ())
|
||||||
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0.png");
|
{
|
||||||
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0-active.png");
|
StatusItem.Image = AnimationFrames [0];
|
||||||
|
StatusItem.AlternateImage = AnimationFramesActive [0];
|
||||||
StatusItem.Image.Size = new SizeF (16, 16);
|
StatusItem.Image.Size = new SizeF (16, 16);
|
||||||
StatusItem.AlternateImage.Size = new SizeF (16, 16);
|
StatusItem.AlternateImage.Size = new SizeF (16, 16);
|
||||||
|
|
||||||
|
@ -149,7 +163,7 @@ namespace SparkleShare {
|
||||||
Program.Controller.OpenSparkleShareFolder ();
|
Program.Controller.OpenSparkleShareFolder ();
|
||||||
};
|
};
|
||||||
|
|
||||||
FolderMenuItem.Image = NSImage.ImageNamed ("sparkleshare-mac");
|
FolderMenuItem.Image = SparkleShareImage;
|
||||||
FolderMenuItem.Image.Size = new SizeF (16, 16);
|
FolderMenuItem.Image.Size = new SizeF (16, 16);
|
||||||
|
|
||||||
Menu.AddItem (FolderMenuItem);
|
Menu.AddItem (FolderMenuItem);
|
||||||
|
@ -166,9 +180,10 @@ namespace SparkleShare {
|
||||||
item.Title = folder_name;
|
item.Title = folder_name;
|
||||||
|
|
||||||
if (Program.Controller.UnsyncedFolders.Contains (folder_name))
|
if (Program.Controller.UnsyncedFolders.Contains (folder_name))
|
||||||
item.Image = NSImage.ImageNamed ("NSCaution");
|
item.Image = CautionImage;
|
||||||
else
|
else
|
||||||
item.Image = NSImage.ImageNamed ("NSFolder");
|
item.Image = FolderImage;
|
||||||
|
|
||||||
item.Image.Size = new SizeF (16, 16);
|
item.Image.Size = new SizeF (16, 16);
|
||||||
Tasks [i] = OpenFolderDelegate (folder_name);
|
Tasks [i] = OpenFolderDelegate (folder_name);
|
||||||
|
|
||||||
|
@ -298,6 +313,22 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
FrameNumber = 0;
|
FrameNumber = 0;
|
||||||
|
|
||||||
|
AnimationFrames = new NSImage [] {
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle0.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle1.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle2.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle3.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle4.png"))
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFramesActive = new NSImage [] {
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle0-active.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle1-active.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle2-active.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle3-active.png")),
|
||||||
|
new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle4-active.png"))
|
||||||
|
};
|
||||||
|
|
||||||
Timer Animation = new Timer () {
|
Timer Animation = new Timer () {
|
||||||
Interval = 40
|
Interval = 40
|
||||||
};
|
};
|
||||||
|
@ -309,14 +340,8 @@ namespace SparkleShare {
|
||||||
FrameNumber = 0;
|
FrameNumber = 0;
|
||||||
|
|
||||||
InvokeOnMainThread (delegate {
|
InvokeOnMainThread (delegate {
|
||||||
string image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
|
StatusItem.Image = AnimationFrames [FrameNumber];
|
||||||
"Pixmaps", "idle" + FrameNumber + ".png");
|
StatusItem.AlternateImage = AnimationFramesActive [FrameNumber];
|
||||||
|
|
||||||
string alternate_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
|
|
||||||
"Pixmaps", "idle" + FrameNumber + "-active.png");
|
|
||||||
|
|
||||||
StatusItem.Image = new NSImage (image_path);
|
|
||||||
StatusItem.AlternateImage = new NSImage (alternate_image_path);
|
|
||||||
StatusItem.Image.Size = new SizeF (16, 16);
|
StatusItem.Image.Size = new SizeF (16, 16);
|
||||||
StatusItem.AlternateImage.Size = new SizeF (16, 16);
|
StatusItem.AlternateImage.Size = new SizeF (16, 16);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue