-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.fs
49 lines (40 loc) · 1.63 KB
/
Main.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
open System
open AppKit
open Foundation
open ObjCRuntime
open CopyButler
NSApplication.Init ()
let App = NSApplication.SharedApplication
let toggleMenuItem (mi : NSMenuItem) =
match mi.State with
| NSCellStateValue.On ->
mi.State <- NSCellStateValue.Off
false
| NSCellStateValue.Off ->
mi.State <- NSCellStateValue.On
true
| _ -> failwith "Unexpected NSCellStateValue"
let pasteboardStack = PasteboardStack(NSPasteboard.GeneralPasteboard)
let mutable pasteboardTimer : NSTimer option = None
let enablePasteboardTimer enabled =
match enabled, pasteboardTimer with
| true, None ->
pasteboardTimer <- NSTimer.CreateRepeatingScheduledTimer(0.3, fun _ -> pasteboardStack.CheckAndPushIfNecessary()) |> Some
| false, Some t ->
t.Invalidate()
pasteboardTimer <- None
| _, _ -> ()
type AppDelegate() =
inherit NSApplicationDelegate()
let mutable item : NSStatusItem = null
override this.DidFinishLaunching(_) =
item <- NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Square)
item.Button.Title <- "🍻"
let menu = new NSMenu()
menu.AddItem <| new NSMenuItem("Enable Copy/Paste Stack", fun s e -> s :?> _ |> toggleMenuItem |> enablePasteboardTimer)
menu.AddItem <| new NSMenuItem("Clear Stack", fun s e -> pasteboardStack.Clear())
menu.AddItem <| NSMenuItem.SeparatorItem
menu.AddItem <| new NSMenuItem("Quit", fun s e -> App.Terminate(this))
item.Menu <- menu
App.Delegate <- new AppDelegate() :> INSApplicationDelegate
NSApplication.Main(Environment.GetCommandLineArgs())