forked from tanshuai/alphabiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-build.js
95 lines (93 loc) · 2.81 KB
/
post-build.js
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
/**
* @description
* A post-build script for adding extension settings
*/
const { existsSync, readFileSync, writeFileSync, copyFileSync } = require('fs')
const { resolve } = require('path')
const audioExt = [
'mp3', 'wav', 'aac', 'flac', 'm4a', 'wma'
]
const videoExt = [
'mp4', 'mkv', 'flv', 'avi', 'mov', 'wmv', 'rmvb', 'flv', 'webm'
]
const srcIconPath = resolve(__dirname, 'public/favicon.ico')
const iconPath = 'favicon.ico'
const buildDarwin = () => {
const plist = require('plist')
const appPath = resolve(__dirname, 'build/electron/Alphabiz-darwin-x64/Alphabiz.app')
const contentsPath = resolve(appPath, 'Contents')
const resourcesPath = resolve(contentsPath, 'Resources')
const infoPlistPath = resolve(contentsPath, 'Info.plist')
if (!existsSync(infoPlistPath)) return console.warn(`Cannot find info.plist at ${infoPlistPath}`)
const infoPlist = plist.parse(readFileSync(infoPlistPath, 'utf-8'))
infoPlist.CFBundleDocumentTypes = [
{
CFBundleTypeExtensions: ['torrent'],
CFBundleTypeIconFile: iconPath,
CFBundleTypeName: 'BitTorrent Document',
CFBundleTypeRole: 'Editor',
LSHandlerRank: 'Owner',
LSItemContentTypes: ['org.bittorrent.torrent']
},
{
CFBundleTypeExtensions: videoExt,
CFBundleTypeIconFile: iconPath,
CFBundleTypeRole: 'Viewer',
LSHandlerRank: 'Owner'
},
{
CFBundleTypeExtensions: audioExt,
CFBundleTypeIconFile: iconPath,
CFBundleTypeRole: 'Viewer',
LSHandlerRank: 'Owner'
},
{
CFBundleTypeName: 'Any',
CFBundleTypeOSTypes: ['****'],
CFBundleTypeRole: 'Editor',
LSHandlerRank: 'Owner',
LSTypeIsPackage: false
}
]
infoPlist.CFBundleURLTypes = [
{
CFBundleTypeRole: 'Editor',
CFBundleURLIconFile: iconPath,
CFBundleURLName: 'BitTorrent Magnet URL',
CFBundleURLSchemes: ['magnet']
},
{
CFBundleTypeRole: 'Editor',
CFBundleURLIconFile: iconPath,
CFBundleURLName: 'BitTorrent Stream-Magnet URL',
CFBundleURLSchemes: ['stream-magnet']
}
]
infoPlist.UTExportedTypeDeclarations = [
{
UTTypeConformsTo: [
'public.data',
'public.item',
'com.bittorrent.torrent'
],
UTTypeDescription: 'BitTorrent Document',
UTTypeIconFile: iconPath,
UTTypeIdentifier: 'org.bittorrent.torrent',
UTTypeReferenceURL: 'http://www.bittorrent.org/beps/bep_0000.html',
UTTypeTagSpecification: {
'com.apple.ostype': 'TORR',
'public.filename-extension': ['torrent'],
'public.mime-type': 'application/x-bittorrent'
}
}
]
writeFileSync(infoPlistPath, plist.build(infoPlist))
copyFileSync(srcIconPath, resolve(resourcesPath, iconPath))
}
switch (process.platform) {
case 'darwin':
buildDarwin()
break;
default:
break;
}