Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 1 addition & 0 deletions ObjC/Base.lproj/MainMenu.nib/designable.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ObjC/Base.lproj/MainMenu.nib/keyedobjects.nib
Binary file not shown.
8 changes: 8 additions & 0 deletions dotNET/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin
obj
*.DotSettings
/build/.nuget/
/out
.vs
packages
.DS_Store
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images": [
{
"filename": "AppIcon-16.png",
"size": "16x16",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-16@2x.png",
"size": "16x16",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-32.png",
"size": "32x32",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-32@2x.png",
"size": "32x32",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-128.png",
"size": "128x128",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-128@2x.png",
"size": "128x128",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-256.png",
"size": "256x256",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-256@2x.png",
"size": "256x256",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-512.png",
"size": "512x512",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-512@2x.png",
"size": "512x512",
"scale": "2x",
"idiom": "mac"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
6 changes: 6 additions & 0 deletions dotNET/DockTile.NET.Plugin/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
81 changes: 81 additions & 0 deletions dotNET/DockTile.NET.Plugin/DockTile.NET.Plugin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{87623BBC-CC8E-4977-B411-FF3ACA8DA0BF}</ProjectGuid>
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>DockTile.NET.Plugin</RootNamespace>
<AssemblyName>DockTile.NET.docktileplugin</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\DockTile.NET\bin\Debug\DockTile.NET.app\Contents\Plugins</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnableCodeSigning>false</EnableCodeSigning>
<CodeSigningKey>Mac Developer</CodeSigningKey>
<CreatePackage>false</CreatePackage>
<EnablePackageSigning>false</EnablePackageSigning>
<IncludeMonoRuntime>false</IncludeMonoRuntime>
<UseSGen>true</UseSGen>
<UseRefCounting>true</UseRefCounting>
<Profiling>true</Profiling>
<HttpClientHandler></HttpClientHandler>
<LinkMode></LinkMode>
<XamMacArch></XamMacArch>
<AOTMode>None</AOTMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\DockTile.NET\bin\Release\DockTile.NET.app\Contents\Plugins</OutputPath>
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnableCodeSigning>false</EnableCodeSigning>
<CreatePackage>true</CreatePackage>
<EnablePackageSigning>false</EnablePackageSigning>
<IncludeMonoRuntime>true</IncludeMonoRuntime>
<UseSGen>true</UseSGen>
<UseRefCounting>true</UseRefCounting>
<LinkMode>SdkOnly</LinkMode>
<HttpClientHandler></HttpClientHandler>
<XamMacArch></XamMacArch>
<AOTMode>None</AOTMode>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-128.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-128%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-16.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-16%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-256.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-256%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-32.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-32%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-512.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-512%402x.png" />
<ImageAsset Include="Assets.xcassets\Contents.json" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="DockTilePlugin.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
</Project>
70 changes: 70 additions & 0 deletions dotNET/DockTile.NET.Plugin/DockTilePlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using AppKit;
using CoreFoundation;
using Foundation;

namespace DockTile.NET.Plugin
{
[Register("DockTilePlugin")]
public class DockTilePlugin : NSDockTilePlugIn
{
private NSMenu nonRuntimeDockMenu;
private const string appId = "com.CartBlanche.DockTile-NET";
private NSObject highScoreObserver;

public override NSMenu DockMenu()
{
// Lazy load our dockMenu
if (nonRuntimeDockMenu == null)
{
nonRuntimeDockMenu = new NSMenu();
}
else
{
nonRuntimeDockMenu.RemoveAllItems();
}

if (CFPreferences.AppSynchronize(appId))
{
nonRuntimeDockMenu.AddItem(new NSMenuItem(string.Format("HighScore: {0}", CFPreferences.GetAppIntegerValue("HighScore", appId))));
}
else
{
nonRuntimeDockMenu.AddItem(new NSMenuItem("HighScore: None"));
}

return nonRuntimeDockMenu;
}

public override void SetDockTile(NSDockTile dockTile)
{
if (dockTile != null)
{
// Attach an observer that will update the high score in the dock tile whenever it changes
highScoreObserver = (NSObject)NSDistributedNotificationCenter.GetDefaultCenter().AddObserver("com.apple.DockTile.NET.HighScoreChanged", null, null, (obj) => {
// Note that this block captures (and retains) dockTile for use later.
// Also note that it does not capture self, which means -dealloc may be called even while the notification is active.
// Although it's not clear this needs to be supported, this does eliminate a potential source of leaks.
UpdateScore(dockTile);
} );

// Make sure score is updated from the get-go as well
UpdateScore(dockTile);
}
else
{
// Strictly speaking this may not be necessary (since the plug-in may be terminated when it's removed from the dock), but it's good practice
NSDistributedNotificationCenter.GetDefaultCenter().RemoveObserver(highScoreObserver);
highScoreObserver = null;
}
}

public static void UpdateScore(NSDockTile dockTile)
{
CFPreferences.AppSynchronize(appId);

dockTile.BadgeLabel = string.Format("{0}", CFPreferences.GetAppIntegerValue("HighScore", appId));
}
}

}
28 changes: 28 additions & 0 deletions dotNET/DockTile.NET.Plugin/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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>CFBundleName</key>
<string>DockTile.NET.Plugin</string>
<key>CFBundleIdentifier</key>
<string>com.CartBlanche.DockTile-NET-Plugin</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>NSPrincipalClass</key>
<string>DockTilePlugin</string>
</dict>
</plist>
14 changes: 14 additions & 0 deletions dotNET/DockTile.NET.Plugin/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using AppKit;
using Foundation;

namespace DockTile.NET.Plugin
{
static class MainClass
{
static void Main(string[] args)
{
NSApplication.Init();
//NSApplication.Main(args);
}
}
}
23 changes: 23 additions & 0 deletions dotNET/DockTile.NET.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DockTile.NET", "DockTile.NET\DockTile.NET.csproj", "{200B24B3-8D88-43C8-B1DE-FFF4A6BC1670}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DockTile.NET.Plugin", "DockTile.NET.Plugin\DockTile.NET.Plugin.csproj", "{87623BBC-CC8E-4977-B411-FF3ACA8DA0BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{200B24B3-8D88-43C8-B1DE-FFF4A6BC1670}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{200B24B3-8D88-43C8-B1DE-FFF4A6BC1670}.Debug|Any CPU.Build.0 = Debug|Any CPU
{200B24B3-8D88-43C8-B1DE-FFF4A6BC1670}.Release|Any CPU.ActiveCfg = Release|Any CPU
{200B24B3-8D88-43C8-B1DE-FFF4A6BC1670}.Release|Any CPU.Build.0 = Release|Any CPU
{87623BBC-CC8E-4977-B411-FF3ACA8DA0BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87623BBC-CC8E-4977-B411-FF3ACA8DA0BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87623BBC-CC8E-4977-B411-FF3ACA8DA0BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87623BBC-CC8E-4977-B411-FF3ACA8DA0BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
76 changes: 76 additions & 0 deletions dotNET/DockTile.NET/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using AppKit;
using Foundation;

namespace DockTile.NET
{
[Register("AppDelegate")]
public partial class AppDelegate : NSApplicationDelegate
{
private nint HighScore => NSUserDefaults.StandardUserDefaults.IntForKey(HighScoreKey);

private const string HighScoreKey = "HighScore";
private NSMenu runtimeDockMenu;

public AppDelegate()
{
}

public override void DidFinishLaunching(NSNotification notification)
{
SetHighScore(HighScore + 1);
}

private void SetHighScore(nint newScore)
{
NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;

// We just save the value out, we don't keep a copy of the high score in the app.
defaults.SetInt(newScore, HighScoreKey);

// Save the value out to defaults now. We often don't explicit synchronize, since it's best to let the system take care of it automatically.
// However, in this case since we're asking the plug-in to update the score, synchronizing before the notification ensures that the plug-in sees the latest value.
// Always make sure the value is updated and synchronized before sending out the distributed notification to other processes.
if (!defaults.Synchronize())
{
Console.WriteLine("Synchronize Failed");
return;
}

// And post a notification so the plug-in sees the change.
NSDistributedNotificationCenter.GetDefaultCenter().PostNotificationName("com.apple.DockTile.NET.HighScoreChanged", null);

// Now update the dock tile. Note that a more general way to do this would be to observe the highScore property,
// but we're just keeping things short and sweet here, trying to demo how to write a plug-in.
NSApplication.SharedApplication.DockTile.BadgeLabel = string.Format("{0}", newScore);
}

public override void WillTerminate(NSNotification notification)
{
// Insert code here to tear down your application
}

// This gets called at Runtime when you right click the DockTile
public override NSMenu ApplicationDockMenu(NSApplication sender)
{
if (runtimeDockMenu == null)
{
runtimeDockMenu = new NSMenu();
}
else
{
runtimeDockMenu.RemoveAllItems();
}

runtimeDockMenu.AddItem(new NSMenuItem(string.Format("{0}", HighScore)));

return runtimeDockMenu;
}

//Reset the high score. Simple...
partial void ResetHighScore(NSObject sender)
{
SetHighScore(0);
}
}
}
Loading