cocoawebview 1.0.2 → 1.0.3
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 +4 -4
- data/ext/cocoawebview/cocoawebview.m +29 -0
- data/lib/cocoawebview/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7240d63de747ac45b7873168e15de395138a1fd9ab1c375663458713e3fffe82
|
|
4
|
+
data.tar.gz: 62b822de8bb6a125f0422a43ae08df6b88b5e5defe78b5a6a71b31a1b6095c1f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f7e5bb5e221c9c230bf34704c1ef5e4064dd69467ced99936527f2206484df752b1e1f12734a68b0ba57e8abefea2dc27a22f1806d4158ad75bac9a4bfed595
|
|
7
|
+
data.tar.gz: 6909f3f69fc318f5ac50ae0ea86a62ddb2c21f545afc1efafda63ff057b5591b59fd074b006a2db6b48bb9b314863ce74d94adedce485cc37596568270e5b92a
|
|
@@ -11,6 +11,7 @@ NSApplication *application = nil;
|
|
|
11
11
|
VALUE nsapp_initialize(VALUE self);
|
|
12
12
|
VALUE nsapp_run(VALUE self);
|
|
13
13
|
VALUE nsapp_get_theme(VALUE self);
|
|
14
|
+
VALUE nsapp_get_app_icon(VALUE self, VALUE app_path);
|
|
14
15
|
VALUE nsapp_exit(VALUE self);
|
|
15
16
|
|
|
16
17
|
VALUE nsmenu_initialize(VALUE self);
|
|
@@ -363,6 +364,7 @@ Init_cocoawebview(void)
|
|
|
363
364
|
rb_define_method(rb_mNSAppClass, "initialize", nsapp_initialize, 0);
|
|
364
365
|
rb_define_method(rb_mNSAppClass, "run", nsapp_run, 0);
|
|
365
366
|
rb_define_method(rb_mNSAppClass, "get_theme", nsapp_get_theme, 0);
|
|
367
|
+
rb_define_method(rb_mNSAppClass, "get_app_icon", nsapp_get_app_icon, 1);
|
|
366
368
|
rb_define_method(rb_mNSAppClass, "exit", nsapp_exit, 0);
|
|
367
369
|
|
|
368
370
|
/* Menu */
|
|
@@ -425,6 +427,33 @@ VALUE nsapp_get_theme(VALUE self) {
|
|
|
425
427
|
return rb_utf8_str_new_cstr(utf8);
|
|
426
428
|
}
|
|
427
429
|
|
|
430
|
+
VALUE nsapp_get_app_icon(VALUE self, VALUE app_path) {
|
|
431
|
+
const char *app_path_c = StringValueCStr(app_path);
|
|
432
|
+
NSString *app_path_ns = [[NSString alloc] initWithCString:app_path_c encoding:NSUTF8StringEncoding];
|
|
433
|
+
|
|
434
|
+
// 1. Get icon for the app bundle
|
|
435
|
+
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:app_path_ns];
|
|
436
|
+
if (!icon) return Qnil;
|
|
437
|
+
|
|
438
|
+
// Optional: set desired size
|
|
439
|
+
[icon setSize:NSMakeSize(256, 256)];
|
|
440
|
+
|
|
441
|
+
// 2. Convert NSImage to PNG data
|
|
442
|
+
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
|
|
443
|
+
initWithData:[icon TIFFRepresentation]];
|
|
444
|
+
|
|
445
|
+
NSData *pngData = [rep representationUsingType:NSBitmapImageFileTypePNG
|
|
446
|
+
properties:@{}];
|
|
447
|
+
if (!pngData) return Qnil;
|
|
448
|
+
|
|
449
|
+
// 3. Encode to Base64 string
|
|
450
|
+
NSString *base64 = [pngData base64EncodedStringWithOptions:0];
|
|
451
|
+
const char *utf8 = [base64 UTF8String];
|
|
452
|
+
if (!utf8) return Qnil;
|
|
453
|
+
|
|
454
|
+
return rb_utf8_str_new(utf8, strlen(utf8));
|
|
455
|
+
}
|
|
456
|
+
|
|
428
457
|
VALUE nsapp_exit(VALUE self) {
|
|
429
458
|
[[NSApplication sharedApplication] terminate:nil];
|
|
430
459
|
}
|
data/lib/cocoawebview/version.rb
CHANGED