[osx] Fix crashes in statusitem, caused by freed memory
This commit is contained in:
parent
1509bedd6a
commit
7cc7f98424
|
@ -10,6 +10,12 @@ namespace SparkleShare
|
||||||
public partial class AppDelegate : NSApplicationDelegate
|
public partial class AppDelegate : NSApplicationDelegate
|
||||||
{
|
{
|
||||||
MainWindowController mainWindowController;
|
MainWindowController mainWindowController;
|
||||||
|
NSStatusItem statusItem;
|
||||||
|
|
||||||
|
NSMenu menu;
|
||||||
|
NSMenuItem item;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public AppDelegate ()
|
public AppDelegate ()
|
||||||
{
|
{
|
||||||
|
@ -23,7 +29,7 @@ namespace SparkleShare
|
||||||
// SparkleStatusIcon = new SparkleStatusIcon ();
|
// SparkleStatusIcon = new SparkleStatusIcon ();
|
||||||
|
|
||||||
SparkleRepo repo = new SparkleRepo ("/Users/hbons/SparkleShare/SparkleShare-Test");
|
SparkleRepo repo = new SparkleRepo ("/Users/hbons/SparkleShare/SparkleShare-Test");
|
||||||
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (32);
|
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (32);
|
||||||
|
|
||||||
statusItem.Enabled = true;
|
statusItem.Enabled = true;
|
||||||
|
|
||||||
|
@ -32,11 +38,11 @@ namespace SparkleShare
|
||||||
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);
|
||||||
|
|
||||||
NSMenu menu = new NSMenu() {};
|
menu = new NSMenu() {};
|
||||||
menu.AddItem (new NSMenuItem () { Title="Up to date (102 MB)", Enabled = true });
|
// menu.AddItem (new NSMenuItem () { Title="Up to date (102 MB)", Enabled = true });
|
||||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
// menu.AddItem (NSMenuItem.SeparatorItem);
|
||||||
|
|
||||||
var item = new NSMenuItem () {
|
item = new NSMenuItem () {
|
||||||
Title="SparkleShare", Enabled = true,
|
Title="SparkleShare", Enabled = true,
|
||||||
Action = new Selector ("ddd")
|
Action = new Selector ("ddd")
|
||||||
};
|
};
|
||||||
|
@ -50,7 +56,7 @@ namespace SparkleShare
|
||||||
|
|
||||||
menu.AddItem (item);
|
menu.AddItem (item);
|
||||||
|
|
||||||
var tmp = new NSMenuItem () {
|
/* var tmp = new NSMenuItem () {
|
||||||
Title="gnome-design", Enabled = true,
|
Title="gnome-design", Enabled = true,
|
||||||
Action = new Selector ("ddd")
|
Action = new Selector ("ddd")
|
||||||
};
|
};
|
||||||
|
@ -116,7 +122,7 @@ namespace SparkleShare
|
||||||
|
|
||||||
menu.AddItem (quit_menu_item);
|
menu.AddItem (quit_menu_item);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
statusItem.Menu = menu;
|
statusItem.Menu = menu;
|
||||||
statusItem.HighlightMode = true;
|
statusItem.HighlightMode = true;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
<EnvironmentVariables>
|
<EnvironmentVariables>
|
||||||
<EnvironmentVariables>
|
<EnvironmentVariables>
|
||||||
<Variable name="PATH" value="" />
|
<Variable name="PATH" value="/opt/local/bin" />
|
||||||
</EnvironmentVariables>
|
</EnvironmentVariables>
|
||||||
</EnvironmentVariables>
|
</EnvironmentVariables>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
@ -1,128 +1,171 @@
|
||||||
using System;
|
// SparkleShare, an instant update workflow to Git.
|
||||||
using System.Drawing;
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||||
using MonoMac.Foundation;
|
//
|
||||||
using MonoMac.AppKit;
|
// This program is free software: you can redistribute it and/or modify
|
||||||
using MonoMac.ObjCRuntime;
|
// 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 Gtk;
|
||||||
|
using Mono.Unix;
|
||||||
|
using Mono.Unix.Native;
|
||||||
using SparkleLib;
|
using SparkleLib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace SparkleShare
|
namespace SparkleShare {
|
||||||
{
|
|
||||||
|
|
||||||
[MonoMac.Foundation.Register("AppDelegate")]
|
public class SparkleUI {
|
||||||
public class SparkleUI : NSApplicationDelegate
|
|
||||||
|
public static SparkleStatusIcon StatusIcon;
|
||||||
|
public static List <SparkleLog> OpenLogs;
|
||||||
|
|
||||||
|
|
||||||
|
// Short alias for the translations
|
||||||
|
public static string _(string s)
|
||||||
{
|
{
|
||||||
public void Run () {
|
return Catalog.GetString (s);
|
||||||
NSApplication.Main (new string [1] {""});
|
|
||||||
}
|
}
|
||||||
public SparkleUI () {NSApplication.Init ();
|
|
||||||
|
|
||||||
Console.WriteLine("HI!2");
|
|
||||||
// SparkleFetcher fetch = new SparkleFetcher ("", "");
|
|
||||||
//SparkleRepo repo = new SparkleRepo ("/Users/hbons/Code/SparkleShare");
|
|
||||||
|
|
||||||
// SparkleStatusIcon = new SparkleStatusIcon ();
|
|
||||||
|
|
||||||
|
|
||||||
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (32);
|
public SparkleUI ()
|
||||||
|
{
|
||||||
|
|
||||||
statusItem.Enabled = true;
|
// Initialize the application
|
||||||
|
Application.Init ();
|
||||||
|
|
||||||
statusItem.Image = NSImage.ImageNamed ("sparkleshare-idle.png");
|
// Create the statusicon
|
||||||
statusItem.AlternateImage = NSImage.ImageNamed ("sparkleshare-idle-focus.png");
|
StatusIcon = new SparkleStatusIcon ();
|
||||||
statusItem.Image.Size = new SizeF (16, 16);
|
|
||||||
statusItem.AlternateImage.Size = new SizeF (16, 16);
|
|
||||||
|
|
||||||
NSMenu menu = new NSMenu() {};
|
// Keep track of which event logs are open
|
||||||
menu.AddItem (new NSMenuItem () { Title="Up to date (102 MB)", Enabled = true });
|
SparkleUI.OpenLogs = new List <SparkleLog> ();
|
||||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
|
||||||
|
|
||||||
var item = new NSMenuItem () {
|
SparkleShare.Controller.OnFirstRun += delegate {
|
||||||
Title="SparkleShare", Enabled = true,
|
Application.Invoke (delegate {
|
||||||
Action = new Selector ("ddd")
|
|
||||||
|
SparkleIntro intro = new SparkleIntro ();
|
||||||
|
intro.ShowAll ();
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
item.Activated += delegate {
|
SparkleShare.Controller.OnInvitation += delegate (string invitation_file_path) {
|
||||||
Console.WriteLine ("DDDD");
|
Application.Invoke (delegate {
|
||||||
|
|
||||||
|
SparkleInvitation invitation = new SparkleInvitation (invitation_file_path);
|
||||||
|
invitation.Present ();
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
item.Image = NSImage.ImageNamed ("NSFolder");
|
// Show a bubble when there are new changes
|
||||||
item.Image.Size = new SizeF (16, 16);
|
SparkleShare.Controller.NotificationRaised += delegate (SparkleCommit commit, string repository_path) {
|
||||||
|
|
||||||
menu.AddItem (item);
|
string file_name = "";
|
||||||
|
string message = null;
|
||||||
|
|
||||||
var tmp = new NSMenuItem () {
|
if (commit.Added.Count > 0) {
|
||||||
Title="gnome-design", Enabled = true,
|
|
||||||
Action = new Selector ("ddd")
|
|
||||||
};
|
|
||||||
|
|
||||||
tmp.Activated += delegate {
|
foreach (string added in commit.Added) {
|
||||||
Console.WriteLine ("DDDD");
|
file_name = added;
|
||||||
};
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
tmp.Image = NSImage.ImageNamed ("NSFolder");
|
message = String.Format (_("added ‘{0}’"), file_name);
|
||||||
tmp.Image.Size = new SizeF (16, 16);
|
|
||||||
|
|
||||||
menu.AddItem (tmp);
|
}
|
||||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
|
||||||
|
|
||||||
Console.WriteLine (item.Action.Name);
|
if (commit.Edited.Count > 0) {
|
||||||
|
|
||||||
NSMenuItem sync_menu_item = new NSMenuItem () {
|
foreach (string modified in commit.Edited) {
|
||||||
Title = "Sync Remote Folder..."
|
file_name = modified;
|
||||||
};
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
sync_menu_item.Activated += delegate {
|
message = String.Format (_("edited ‘{0}’"), file_name);
|
||||||
Console.WriteLine ("DDDD");
|
|
||||||
};
|
|
||||||
|
|
||||||
menu.AddItem (sync_menu_item);
|
}
|
||||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
|
||||||
|
|
||||||
NSMenuItem notifications_menu_item = new NSMenuItem () {
|
if (commit.Deleted.Count > 0) {
|
||||||
Title = "Show Notifications",
|
|
||||||
State = NSCellStateValue.On
|
|
||||||
};
|
|
||||||
|
|
||||||
notifications_menu_item.Activated += delegate {
|
foreach (string removed in commit.Deleted) {
|
||||||
statusItem.Image = NSImage.ImageNamed ("NSComputer");
|
file_name = removed;
|
||||||
if (notifications_menu_item.State == NSCellStateValue.On)
|
break;
|
||||||
notifications_menu_item.State = NSCellStateValue.Off;
|
}
|
||||||
|
|
||||||
|
message = String.Format (_("deleted ‘{0}’"), file_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int changes_count = (commit.Added.Count +
|
||||||
|
commit.Edited.Count +
|
||||||
|
commit.Deleted.Count);
|
||||||
|
|
||||||
|
if (changes_count > 1)
|
||||||
|
message += " + " + (changes_count - 1);
|
||||||
|
|
||||||
|
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
|
||||||
|
SparkleBubble bubble = new SparkleBubble (commit.UserName, message);
|
||||||
|
|
||||||
|
string avatar_file_path = SparkleUIHelpers.GetAvatar (commit.UserEmail, 32);
|
||||||
|
|
||||||
|
if (avatar_file_path != null)
|
||||||
|
bubble.Icon = new Gdk.Pixbuf (avatar_file_path);
|
||||||
else
|
else
|
||||||
notifications_menu_item.State = NSCellStateValue.On;
|
bubble.Icon = SparkleUIHelpers.GetIcon ("avatar-default", 32);
|
||||||
|
|
||||||
|
// bubble.AddAction ("", "Show Events", delegate {
|
||||||
|
|
||||||
|
// SparkleLog log = new SparkleLog (repository_path);
|
||||||
|
// log.ShowAll ();
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
// bubble.Show ();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
menu.AddItem (notifications_menu_item);
|
// Show a bubble when there was a conflict
|
||||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
SparkleShare.Controller.ConflictNotificationRaised += delegate {
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
|
||||||
NSMenuItem about_menu_item = new NSMenuItem () {
|
string title = _("Ouch! Mid-air collision!");
|
||||||
Title = "About"
|
string subtext = _("Don't worry, SparkleShare made a copy of each conflicting file.");
|
||||||
|
|
||||||
|
SparkleBubble bubble = new SparkleBubble(title, subtext);
|
||||||
|
// bubble.Show ();
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
about_menu_item.Activated += delegate {
|
|
||||||
Console.WriteLine ("DDDD");
|
|
||||||
statusItem.Title = "bla";
|
|
||||||
};
|
|
||||||
|
|
||||||
menu.AddItem (about_menu_item);
|
|
||||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
|
||||||
|
|
||||||
NSMenuItem quit_menu_item = new NSMenuItem () {
|
|
||||||
Title = "Quit"
|
|
||||||
};
|
|
||||||
quit_menu_item.Activated += delegate {
|
|
||||||
Console.WriteLine ("DDDD");
|
|
||||||
Environment.Exit (0);
|
|
||||||
};
|
|
||||||
|
|
||||||
menu.AddItem (quit_menu_item);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
statusItem.Menu = menu;
|
|
||||||
statusItem.HighlightMode = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Runs the application
|
||||||
|
public void Run ()
|
||||||
|
{
|
||||||
|
|
||||||
|
Application.Run ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue