-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockRestorable.m
148 lines (122 loc) · 3.26 KB
/
DockRestorable.m
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// DockRestorable.m
// FMN
//
// Created by David Noblet on 9/16/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "DockRestorable.h"
#define DOCK CFSTR("com.apple.dock")
#define USER kCFPreferencesCurrentUser
#define HOST kCFPreferencesAnyHost
#define AUTOHIDE CFSTR("autohide")
@implementation DockRestorable
/*- (void) logDockPrefs
{
NSEnumerator *enumerator = [dockPrefs keyEnumerator];
id key;
while ((key = [enumerator nextObject]))
{
id value = [dockPrefs valueForKey: key];
NSLog(@"@@@@@@@@@@ Key: '%@'; Value: '%@' @@@@@@@@@@@@@", key, value);
}
}*/
+ (Boolean) getDockAutohide
{
Boolean success;
return CFPreferencesGetAppBooleanValue (
AUTOHIDE,
DOCK,
&success
) && success;
}
- (id) initWithCurrent
{
self = [super init];
if(!self)
return nil;
NSLog(@"Storing Dock Preferences");
CFPreferencesAppSynchronize(DOCK);
/*NSArray* keys;
keys = (NSArray*) CFPreferencesCopyKeyList (
DOCK,
USER,
HOST
);
dockPrefs = (NSDictionary*) CFPreferencesCopyMultiple (
(CFArrayRef) keys,
DOCK,
USER,
HOST
);
[keys release];*/
autohidePref = [DockRestorable getDockAutohide];
NSLog(@"Storing Dock Autohide Preference: %d",autohidePref);
//[self logDockPrefs];
return self;
}
- (void) restoreWithContext : (NSDictionary*) context
{
NSLog(@"Restoring Dock Preferences");
/*[self logDockPrefs];
CFPreferencesSetMultiple (
(CFDictionaryRef) dockPrefs,
nil,
DOCK,
USER,
HOST
);*/
NSLog(@"Restoring Dock Autohide Preference: %d",autohidePref);
if([DockRestorable getDockAutohide] != autohidePref)
{
CFPreferencesSetValue(
AUTOHIDE,
autohidePref ? kCFBooleanTrue : kCFBooleanFalse,
DOCK,
USER,
HOST
);
CFPreferencesAppSynchronize(DOCK);
/*CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
CFNotificationCenterPostNotification (
center,
CFSTR("com.apple.dock.prefchanged"),
DOCK,
nil, true
);*/
/*
tell application "System Events"
keystroke "d" using {command down, option down}
end tell
*/
NSString *s = [NSString stringWithFormat:
@"tell application \"System Events\"\n"
@"\tkeystroke \"d\" using {command down, option down}\n"
@"end tell\n"];
NSAppleScript *scriptObj = [[NSAppleScript alloc] initWithSource:s];
if (scriptObj)
{
NSDictionary *errInfo;
NSAppleEventDescriptor *aed = [scriptObj executeAndReturnError:&errInfo];
[scriptObj release];
if (!aed)
{
NSLog(@"Got Error in deleteLoginItem");
}
}
}
}
- (int) priority
{
// We want this to be restored before the window positions and sizes
return kRestorableDefaultPriority+1;
}
- (void) dealloc
{
/*if(dockPrefs)
{
[dockPrefs release];
}*/
[super dealloc];
}
@end