[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
|
||||
{
|
||||
MainWindowController mainWindowController;
|
||||
NSStatusItem statusItem;
|
||||
|
||||
NSMenu menu;
|
||||
NSMenuItem item;
|
||||
|
||||
|
||||
|
||||
public AppDelegate ()
|
||||
{
|
||||
|
@ -23,7 +29,7 @@ namespace SparkleShare
|
|||
// SparkleStatusIcon = new SparkleStatusIcon ();
|
||||
|
||||
SparkleRepo repo = new SparkleRepo ("/Users/hbons/SparkleShare/SparkleShare-Test");
|
||||
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (32);
|
||||
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (32);
|
||||
|
||||
statusItem.Enabled = true;
|
||||
|
||||
|
@ -32,11 +38,11 @@ namespace SparkleShare
|
|||
statusItem.Image.Size = new SizeF (16, 16);
|
||||
statusItem.AlternateImage.Size = new SizeF (16, 16);
|
||||
|
||||
NSMenu menu = new NSMenu() {};
|
||||
menu.AddItem (new NSMenuItem () { Title="Up to date (102 MB)", Enabled = true });
|
||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
menu = new NSMenu() {};
|
||||
// menu.AddItem (new NSMenuItem () { Title="Up to date (102 MB)", Enabled = true });
|
||||
// menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
|
||||
var item = new NSMenuItem () {
|
||||
item = new NSMenuItem () {
|
||||
Title="SparkleShare", Enabled = true,
|
||||
Action = new Selector ("ddd")
|
||||
};
|
||||
|
@ -50,7 +56,7 @@ namespace SparkleShare
|
|||
|
||||
menu.AddItem (item);
|
||||
|
||||
var tmp = new NSMenuItem () {
|
||||
/* var tmp = new NSMenuItem () {
|
||||
Title="gnome-design", Enabled = true,
|
||||
Action = new Selector ("ddd")
|
||||
};
|
||||
|
@ -116,7 +122,7 @@ namespace SparkleShare
|
|||
|
||||
menu.AddItem (quit_menu_item);
|
||||
|
||||
|
||||
*/
|
||||
|
||||
statusItem.Menu = menu;
|
||||
statusItem.HighlightMode = true;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<ConsolePause>false</ConsolePause>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariables>
|
||||
<Variable name="PATH" value="" />
|
||||
<Variable name="PATH" value="/opt/local/bin" />
|
||||
</EnvironmentVariables>
|
||||
</EnvironmentVariables>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -1,128 +1,171 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.ObjCRuntime;
|
||||
// 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 Gtk;
|
||||
using Mono.Unix;
|
||||
using Mono.Unix.Native;
|
||||
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 : NSApplicationDelegate
|
||||
{
|
||||
public void Run () {
|
||||
NSApplication.Main (new string [1] {""});
|
||||
public class SparkleUI {
|
||||
|
||||
public static SparkleStatusIcon StatusIcon;
|
||||
public static List <SparkleLog> OpenLogs;
|
||||
|
||||
|
||||
// Short alias for the translations
|
||||
public static string _(string s)
|
||||
{
|
||||
return Catalog.GetString (s);
|
||||
}
|
||||
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");
|
||||
statusItem.AlternateImage = NSImage.ImageNamed ("sparkleshare-idle-focus.png");
|
||||
statusItem.Image.Size = new SizeF (16, 16);
|
||||
statusItem.AlternateImage.Size = new SizeF (16, 16);
|
||||
// Create the statusicon
|
||||
StatusIcon = new SparkleStatusIcon ();
|
||||
|
||||
NSMenu menu = new NSMenu() {};
|
||||
menu.AddItem (new NSMenuItem () { Title="Up to date (102 MB)", Enabled = true });
|
||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
// Keep track of which event logs are open
|
||||
SparkleUI.OpenLogs = new List <SparkleLog> ();
|
||||
|
||||
var item = new NSMenuItem () {
|
||||
Title="SparkleShare", Enabled = true,
|
||||
Action = new Selector ("ddd")
|
||||
SparkleShare.Controller.OnFirstRun += delegate {
|
||||
Application.Invoke (delegate {
|
||||
|
||||
SparkleIntro intro = new SparkleIntro ();
|
||||
intro.ShowAll ();
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
item.Activated += delegate {
|
||||
Console.WriteLine ("DDDD");
|
||||
};
|
||||
SparkleShare.Controller.OnInvitation += delegate (string invitation_file_path) {
|
||||
Application.Invoke (delegate {
|
||||
|
||||
item.Image = NSImage.ImageNamed ("NSFolder");
|
||||
item.Image.Size = new SizeF (16, 16);
|
||||
SparkleInvitation invitation = new SparkleInvitation (invitation_file_path);
|
||||
invitation.Present ();
|
||||
|
||||
menu.AddItem (item);
|
||||
|
||||
var tmp = new NSMenuItem () {
|
||||
Title="gnome-design", Enabled = true,
|
||||
Action = new Selector ("ddd")
|
||||
});
|
||||
};
|
||||
|
||||
tmp.Activated += delegate {
|
||||
Console.WriteLine ("DDDD");
|
||||
};
|
||||
// Show a bubble when there are new changes
|
||||
SparkleShare.Controller.NotificationRaised += delegate (SparkleCommit commit, string repository_path) {
|
||||
|
||||
tmp.Image = NSImage.ImageNamed ("NSFolder");
|
||||
tmp.Image.Size = new SizeF (16, 16);
|
||||
string file_name = "";
|
||||
string message = null;
|
||||
|
||||
menu.AddItem (tmp);
|
||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
if (commit.Added.Count > 0) {
|
||||
|
||||
Console.WriteLine (item.Action.Name);
|
||||
foreach (string added in commit.Added) {
|
||||
file_name = added;
|
||||
break;
|
||||
}
|
||||
|
||||
message = String.Format (_("added ‘{0}’"), file_name);
|
||||
|
||||
}
|
||||
|
||||
if (commit.Edited.Count > 0) {
|
||||
|
||||
foreach (string modified in commit.Edited) {
|
||||
file_name = modified;
|
||||
break;
|
||||
}
|
||||
|
||||
message = String.Format (_("edited ‘{0}’"), file_name);
|
||||
|
||||
}
|
||||
|
||||
if (commit.Deleted.Count > 0) {
|
||||
|
||||
foreach (string removed in commit.Deleted) {
|
||||
file_name = removed;
|
||||
break;
|
||||
}
|
||||
|
||||
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
|
||||
bubble.Icon = SparkleUIHelpers.GetIcon ("avatar-default", 32);
|
||||
|
||||
// bubble.AddAction ("", "Show Events", delegate {
|
||||
|
||||
// SparkleLog log = new SparkleLog (repository_path);
|
||||
// log.ShowAll ();
|
||||
|
||||
// });
|
||||
|
||||
// bubble.Show ();
|
||||
|
||||
});
|
||||
|
||||
NSMenuItem sync_menu_item = new NSMenuItem () {
|
||||
Title = "Sync Remote Folder..."
|
||||
};
|
||||
|
||||
sync_menu_item.Activated += delegate {
|
||||
Console.WriteLine ("DDDD");
|
||||
};
|
||||
// Show a bubble when there was a conflict
|
||||
SparkleShare.Controller.ConflictNotificationRaised += delegate {
|
||||
Application.Invoke (delegate {
|
||||
|
||||
menu.AddItem (sync_menu_item);
|
||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
string title = _("Ouch! Mid-air collision!");
|
||||
string subtext = _("Don't worry, SparkleShare made a copy of each conflicting file.");
|
||||
|
||||
NSMenuItem notifications_menu_item = new NSMenuItem () {
|
||||
Title = "Show Notifications",
|
||||
State = NSCellStateValue.On
|
||||
SparkleBubble bubble = new SparkleBubble(title, subtext);
|
||||
// bubble.Show ();
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
notifications_menu_item.Activated += delegate {
|
||||
statusItem.Image = NSImage.ImageNamed ("NSComputer");
|
||||
if (notifications_menu_item.State == NSCellStateValue.On)
|
||||
notifications_menu_item.State = NSCellStateValue.Off;
|
||||
else
|
||||
notifications_menu_item.State = NSCellStateValue.On;
|
||||
};
|
||||
|
||||
menu.AddItem (notifications_menu_item);
|
||||
menu.AddItem (NSMenuItem.SeparatorItem);
|
||||
|
||||
NSMenuItem about_menu_item = new NSMenuItem () {
|
||||
Title = "About"
|
||||
};
|
||||
|
||||
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