cocoadock 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b4e20bb778be0635e07ee877840cee13af33fce3d809dcb561b73fad2d6b753b
4
+ data.tar.gz: '039819d9514d0a4c74b466363ba864cdb25489f28317e4f9c862d6076083304c'
5
+ SHA512:
6
+ metadata.gz: e058a48e31c7a80115fc71aedf39213e2644d5fad98604e5106ae59ff0e36ba237db1d6392077df87ae380e4c1934241296685fede7f0a9faa93087157ba4f0a
7
+ data.tar.gz: b0b07f1c8f8812e0f0f7052be2dac354e8e538e74b6f3805959e4a4c16061097778d722563ef69f6bcdc9c775f9be58cd7d9a9ad379216be3ce70aa9e432e7a0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Tommy Jeff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Cocoadock
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cocoadock`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cocoadock.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/extensiontask"
5
+
6
+ task build: :compile
7
+
8
+ GEMSPEC = Gem::Specification.load("cocoadock.gemspec")
9
+
10
+ Rake::ExtensionTask.new("cocoadock", GEMSPEC) do |ext|
11
+ ext.lib_dir = "lib/cocoadock"
12
+ end
13
+
14
+ task default: %i[clobber compile]
@@ -0,0 +1,6 @@
1
+ #ifndef COCOADOCK_H
2
+ #define COCOADOCK_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* COCOADOCK_H */
@@ -0,0 +1,100 @@
1
+ #import <Cocoa/Cocoa.h>
2
+ #include "cocoadock.h"
3
+
4
+ VALUE rb_mCocoadock;
5
+ VALUE rb_mCocoadockClass;
6
+
7
+ VALUE cocoadock_initialize(VALUE self);
8
+ VALUE cocoadock_add_app_to_dock(VALUE self, VALUE path);
9
+ VALUE cocoadock_remove_app_from_dock(VALUE self, VALUE path);
10
+
11
+ void addAppToDock(const char *app_path) {
12
+ NSString *appPath = [[NSString alloc] initWithCString:app_path encoding:NSUTF8StringEncoding];
13
+
14
+ // Convert to file URL with percent escapes
15
+ NSURL *appURL = [NSURL fileURLWithPath:appPath];
16
+ NSString *urlString = appURL.absoluteString;
17
+
18
+ // Now form the Dock entry
19
+ NSString *dockEntry = [NSString stringWithFormat:
20
+ @"'<dict>"
21
+ "<key>tile-data</key><dict>"
22
+ "<key>file-data</key><dict>"
23
+ "<key>_CFURLString</key><string>%@</string>"
24
+ "<key>_CFURLStringType</key><integer>15</integer>"
25
+ "</dict>"
26
+ "</dict>"
27
+ "</dict>'", urlString];
28
+
29
+ NSString *command = [NSString stringWithFormat:
30
+ @"defaults write com.apple.dock persistent-apps -array-add %@ && killall Dock", dockEntry];
31
+
32
+ // Execute the command
33
+ NSTask *task = [[NSTask alloc] init];
34
+ task.launchPath = @"/bin/sh";
35
+ task.arguments = @[@"-c", command];
36
+ [task launch];
37
+ }
38
+
39
+ void removeAppFromDock(const char* app_path) {
40
+ NSString *appPath = [[NSString alloc] initWithCString:app_path encoding:NSUTF8StringEncoding];
41
+ NSURL *appURL = [NSURL fileURLWithPath:appPath];
42
+ NSString *urlString = appURL.absoluteString;
43
+
44
+ // Step 1: Export current Dock preferences
45
+ NSString *exportPlistCmd = @"defaults export com.apple.dock - > /tmp/com.apple.dock.plist";
46
+ system([exportPlistCmd UTF8String]);
47
+
48
+ // Step 2: Load the plist
49
+ NSMutableDictionary *dockPlist = [NSMutableDictionary dictionaryWithContentsOfFile:@"/tmp/com.apple.dock.plist"];
50
+ NSMutableArray *persistentApps = [dockPlist[@"persistent-apps"] mutableCopy];
51
+ if (!persistentApps) return;
52
+
53
+ // Step 3: Filter out the app by matching its _CFURLString
54
+ NSMutableArray *filtered = [NSMutableArray array];
55
+ for (NSDictionary *entry in persistentApps) {
56
+ NSDictionary *tileData = entry[@"tile-data"];
57
+ NSDictionary *fileData = tileData[@"file-data"];
58
+ NSString *entryURL = fileData[@"_CFURLString"];
59
+ if (![entryURL isEqualToString:urlString]) {
60
+ [filtered addObject:entry];
61
+ }
62
+ }
63
+
64
+ // Step 4: Save updated plist and re-import
65
+ dockPlist[@"persistent-apps"] = filtered;
66
+ [dockPlist writeToFile:@"/tmp/com.apple.dock.plist" atomically:YES];
67
+
68
+ NSString *importCmd = @"defaults import com.apple.dock /tmp/com.apple.dock.plist";
69
+ system([importCmd UTF8String]);
70
+
71
+ // Step 5: Restart Dock
72
+ system("killall Dock");
73
+ }
74
+
75
+ RUBY_FUNC_EXPORTED void
76
+ Init_cocoadock(void)
77
+ {
78
+ rb_mCocoadock = rb_define_module("CocoaDock");
79
+ rb_mCocoadockClass = rb_define_class_under(rb_mCocoadock, "CocoaDock", rb_cObject);
80
+ rb_define_method(rb_mCocoadockClass, "initialize", cocoadock_initialize, 0);
81
+ rb_define_method(rb_mCocoadockClass, "add_app", cocoadock_add_app_to_dock, 1);
82
+ rb_define_method(rb_mCocoadockClass, "remove_app", cocoadock_remove_app_from_dock, 1);
83
+ }
84
+
85
+ VALUE cocoadock_initialize(VALUE self) {
86
+ rb_iv_set(self, "@var", rb_hash_new());
87
+ return self;
88
+ }
89
+
90
+ VALUE cocoadock_add_app_to_dock(VALUE self, VALUE path) {
91
+ const char *c_app_path = StringValueCStr(path);
92
+ //NSString *appPath = [[NSString alloc] initWithCString:c_app_path encoding:NSUTF8StringEncoding];
93
+ addAppToDock(c_app_path);
94
+ }
95
+
96
+ VALUE cocoadock_remove_app_from_dock(VALUE self, VALUE path) {
97
+ const char *c_app_path = StringValueCStr(path);
98
+ //NSString *appPath = [[NSString alloc] initWithCString:c_app_path encoding:NSUTF8StringEncoding];
99
+ removeAppFromDock(c_app_path);
100
+ }
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ # Makes all symbols private by default to avoid unintended conflict
6
+ # with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
7
+ # selectively, or entirely remove this flag.
8
+ append_cflags("-fvisibility=hidden")
9
+
10
+ have_framework("Cocoa")
11
+
12
+ $CFLAGS << " -ObjC"
13
+
14
+ # Add Cocoa framework to linker flags
15
+ $LDFLAGS << " -framework Cocoa"
16
+
17
+ create_makefile("cocoadock/cocoadock")
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocoadock
4
+ VERSION = "0.1.0"
5
+ end
data/lib/cocoadock.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cocoadock/version"
4
+ require_relative "cocoadock/cocoadock"
5
+
6
+ module CocoaDock
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+
10
+ class CocoaDock
11
+
12
+ end
13
+ end
data/sig/cocoadock.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Cocoadock
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoadock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tommy Jeff
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-07-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Cocoa dock functions for Ruby on macOS
13
+ email:
14
+ - threcius@yahoo.com
15
+ executables: []
16
+ extensions:
17
+ - ext/cocoadock/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - Rakefile
23
+ - ext/cocoadock/cocoadock.h
24
+ - ext/cocoadock/cocoadock.m
25
+ - ext/cocoadock/extconf.rb
26
+ - lib/cocoadock.rb
27
+ - lib/cocoadock/version.rb
28
+ - sig/cocoadock.rbs
29
+ homepage: https://github.com/orklann/cocoadock
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ homepage_uri: https://github.com/orklann/cocoadock
34
+ source_code_uri: https://github.com/orklann/cocoadock
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.6.5
50
+ specification_version: 4
51
+ summary: Cocoa dock functions for Ruby on macOS
52
+ test_files: []