Skip to content

Commit

Permalink
mac: Use updated Xamarin.Mac APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
hbons committed Sep 10, 2017
1 parent 0fc9756 commit 122b69f
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 189 deletions.
51 changes: 27 additions & 24 deletions SparkleShare/Mac/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SparkleShare, a collaboration and sharing tool.
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -67,10 +67,14 @@ public override void Initialize ()

public override void CreateSparkleShareFolder ()
{
if (!Directory.Exists (SparkleShare.Controller.FoldersPath)) {
Directory.CreateDirectory (SparkleShare.Controller.FoldersPath);
Syscall.chmod (SparkleShare.Controller.FoldersPath, (FilePermissions) 448); // 448 -> 700
}
if (Directory.Exists (SparkleShare.Controller.FoldersPath))
return;

Directory.CreateDirectory (SparkleShare.Controller.FoldersPath);

// TODO: Use proper API
var chmod = new Command ("chmod", "700 " + SparkleShare.Controller.FoldersPath);
chmod.StartAndWaitForExit ();
}


Expand All @@ -89,31 +93,31 @@ public override void SetFolderIcon ()
}


// There aren't any bindings in Xamarin.Mac to support this yet, so
// we call out to an applescript to do the job
// There aren't any bindings in Xamarin.Mac to support this yet, so
// we call out to an applescript to do the job
public override void CreateStartupItem ()
{
string args = "-e 'tell application \"System Events\" to " +
"make login item at end with properties " +
"{path:\"" + NSBundle.MainBundle.BundlePath + "\", hidden:false}'";
var process = new Command ("osascript", args);
process.StartAndWaitForExit ();
Logger.LogInfo ("Controller", "Added " + NSBundle.MainBundle.BundlePath + " to login items");
}
string args = "-e 'tell application \"System Events\" to " +
"make login item at end with properties " +
"{path:\"" + NSBundle.MainBundle.BundlePath + "\", hidden:false}'";

var process = new Command ("osascript", args);
process.StartAndWaitForExit ();

Logger.LogInfo ("Controller", "Added " + NSBundle.MainBundle.BundlePath + " to login items");
}


public override void InstallProtocolHandler ()
{
}


public override void CopyToClipboard (string text)
{
NSPasteboard.GeneralPasteboard.ClearContents ();
NSPasteboard.GeneralPasteboard.SetStringForType (text, "NSStringPboardType");
}
public override void CopyToClipboard (string text)
{
NSPasteboard.GeneralPasteboard.ClearContents ();
NSPasteboard.GeneralPasteboard.SetStringForType (text, "NSStringPboardType");
}


public override void OpenFolder (string path)
Expand Down Expand Up @@ -216,13 +220,12 @@ void OnFilesChanged (List<string> changed_files_in_basedir)


public delegate void Code ();
readonly NSObject obj = new NSObject ();

public void Invoke (Code code)
{
using (var a = new NSAutoreleasePool ())
{
obj.InvokeOnMainThread (() => code ());
new NSObject ().InvokeOnMainThread (() => code ());
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions SparkleShare/Mac/UserInterface/About.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SparkleShare, a collaboration and sharing tool.
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -16,9 +16,9 @@


using System;
using System.Drawing;

using AppKit;
using CoreGraphics;
using Foundation;

namespace SparkleShare {
Expand All @@ -38,21 +38,21 @@ public About (IntPtr handle) : base (handle) { }

public About () : base ()
{
SetFrame (new RectangleF (0, 0, 640, 281), true);
SetFrame (new CGRect (0, 0, 640, 281), true);
Center ();

Delegate = new SparkleAboutDelegate ();
StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled);
Title = "About SparkleShare";
MaxSize = new SizeF (640, 281);
MinSize = new SizeF (640, 281);
MaxSize = new CGSize (640, 281);
MinSize = new CGSize (640, 281);
HasShadow = true;
IsOpaque = false;
BackingType = NSBackingStore.Buffered;
Level = NSWindowLevel.Floating;

this.hidden_close_button = new NSButton () {
Frame = new RectangleF (0, 0, 0, 0),
Frame = new CGRect (0, 0, 0, 0),
KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
KeyEquivalent = "w"
};
Expand Down Expand Up @@ -82,22 +82,22 @@ public About () : base ()
private void CreateAbout ()
{
this.about_image = NSImage.ImageNamed ("about");
this.about_image.Size = new SizeF (720, 260);
this.about_image.Size = new CGSize (720, 260);

this.about_image_view = new NSImageView () {
Image = this.about_image,
Frame = new RectangleF (0, 0, 720, 260)
Frame = new CGRect (0, 0, 720, 260)
};

this.version_text_field = new SparkleLabel ("version " + Controller.RunningVersion, NSTextAlignment.Left) {
DrawsBackground = false,
Frame = new RectangleF (295, 140, 318, 22),
Frame = new CGRect (295, 140, 318, 22),
TextColor = NSColor.White
};

this.updates_text_field = new SparkleLabel ("Checking for updates...", NSTextAlignment.Left) {
DrawsBackground = false,
Frame = new RectangleF (295, Frame.Height - 232, 318, 98),
Frame = new CGRect (295, Frame.Height - 232, 318, 98),
TextColor = NSColor.FromCalibratedRgba (1.0f, 1.0f, 1.0f, 0.5f)
};

Expand All @@ -108,26 +108,26 @@ private void CreateAbout ()
"under the GNU GPLv3", NSTextAlignment.Left) {

DrawsBackground = false,
Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
Frame = new CGRect (295, Frame.Height - 260, 318, 98),
TextColor = NSColor.White
};

this.website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress);
this.website_link.Frame = new RectangleF (new PointF (295, 25), this.website_link.Frame.Size);
this.website_link.Frame = new CGRect (new CGPoint (295, 25), this.website_link.Frame.Size);

this.credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress);
this.credits_link.Frame = new RectangleF (
new PointF (this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25),
this.credits_link.Frame = new CGRect (
new CGPoint (this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25),
this.credits_link.Frame.Size);

this.report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress);
this.report_problem_link.Frame = new RectangleF (
new PointF (this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25),
this.report_problem_link.Frame = new CGRect (
new CGPoint (this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25),
this.report_problem_link.Frame.Size);

this.debug_log_link = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress);
this.debug_log_link.Frame = new RectangleF (
new PointF (this.report_problem_link.Frame.X + this.report_problem_link.Frame.Width + 10, 25),
this.debug_log_link.Frame = new CGRect (
new CGPoint (this.report_problem_link.Frame.X + this.report_problem_link.Frame.Width + 10, 25),
this.debug_log_link.Frame.Size);

ContentView.AddSubview (this.about_image_view);
Expand Down
2 changes: 1 addition & 1 deletion SparkleShare/Mac/UserInterface/Bubbles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void ShowBubbleEvent (string title, string subtext, string image_path) {
var notification = new NSUserNotification {
Title = title,
InformativeText = subtext,
DeliveryDate = DateTime.Now
DeliveryDate = (NSDate) DateTime.Now
};

NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;
Expand Down
Loading

0 comments on commit 122b69f

Please sign in to comment.