ウェブサイト検索

javascript - Electron - アプリケーションがMac OSで実行されているかどうかをどうやって理解できますか、それはファイルタイプに関連していますか、それとも関係ありませんか?


私は Electron 上で Mac OS アプリケーションを作成しています。

私のアプリケーションは特定の種類のファイルと関連付けられています。別のアプリケーションがその関連付けを自分に切り替えることがあります。アプリケーションが実行中に、アプリケーションがファイルと関連付けられているかどうかを確認する必要があります。アプリケーションがファイルと関連付けられていない場合は、ユーザーにこれを通知してください。

この方法を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\', \'****\'' }

ファイルをダブルクリックしたときにアプリケーションが起動するかどうかはどうすればわかりますか?