Electron - Как я могу понять, когда приложение работает в ОС Ma c, связано это с типом файла или нет? - PullRequest
2 голосов
/ 19 июня 2020

Я создаю приложение Ma c OS на Electron .

My application is связано с определенными типами файлов . Другое приложение может переключить ассоциацию на себя. Пока приложение работает, мне нужно проверить, связано ли приложение с файлами. Если приложение не связано с файлом, сообщите об этом пользователю.

Скажите, пожалуйста, как это можно сделать с помощью NodeJS и / или Electron ?

{
   "appId": "com.example.app",
   "files": ["build", "static", "index.js"],
   "fileAssociations": [
        {
            "ext": ["txt", "md", "yml"],
            "name": "Plain Text",
            "role": "Editor"
        }
    ],
    "mac": {
        "target": [
            {
                "target": "dmg",
                "arch": [
                    "x64"
                ]
            }
        ]
    }
}

При использовании

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -dump

Вы можете получить информацию об ассоциациях файлов с приложениями.

Например, в моем случае я получил от дамп:

  { 'type id': ' ',
    'claim id': 'Plain Text (UTF-16) (0x1258)',
    uti: ' ',
    flags:
     'apple-internal  doc-type  resolves-icloud-conflicts (0000000000000222)',
    'conforms to': ' ',
    tags: ' ',
    rank: 'Default',
    bundle: 'System Information (0x31c)',
    roles: 'None (0000000000000001)',
    bindings: '.txt' },
    
  { 'type id': 'public.plain-text (0x150c)',
    'claim id': ' ',
    uti: 'public.plain-text',
    flags:
     'active  public  apple-internal  exported  core  trusted (0000000000000077)',
    'conforms to': 'public.text',
    tags: '.txt, .text, text/plain',
    rank: ' ',
    bundle: 'CoreTypes (0x21c)',
    roles: ' ',
    bindings: ' ' },
    
  { 'type id': ' ',
    'claim id': '6008 (0x1778)',
    uti: ' ',
    flags: 'doc-type (0000000000000020)',
    'conforms to': ' ',
    tags: ' ',
    rank: 'Default',
    bundle: 'Sublime Text (0x614)',
    roles: 'Editor (0000000000000004)',
    bindings: '.txt' },
    
  { 'type id': ' ',
    'claim id': 'Visual Studio Code document (0x16a0)',
    uti: ' ',
    flags:
     'relative-icon-path  legacy-wildcard  doc-type (0000000000000034)',
    'conforms to': ' ',
    tags: ' ',
    rank: 'Default',
    bundle: 'Code (0x600)',
    roles: 'Editor (0000000000000004)',
    bindings:
     '.clj, .cljs, .cljx, .clojure, .code-workspace, .coffee, .ctp, .dockerfile, .dot, .edn, .fs, .fsi, .fsscript, .fsx, .handlebars, .hbs, .lua, .m, .makefile, .ml, .mli, .pl, .pl6, .pm, .pm6, .pod, .pp, .properties, .psgi, .pug, .r, .rs, .rt, .svg, .svgz, .t, .txt, .vb, .xcodeproj, .xcworkspace, \'TEXT\', \'utxt\', \'TUTX\', \'****\'' }

Как мне узнать, запустится ли мое приложение, когда я дважды щелкну файл?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...