Skip to content

Commit 6778ca9

Browse files
committed
fix(device): Mac is not allow excusive right to use USB
1 parent 79b684d commit 6778ca9

File tree

6 files changed

+147
-5
lines changed

6 files changed

+147
-5
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ before_script:
1515
- npm run lint
1616

1717
script:
18-
- cd ./test-serializer && node ./test-serializer.js
18+
- npm run test
19+
- npm run release
1920

2021
cache:
2122
directories:

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ install:
2121
- npm install
2222

2323
test_script:
24-
- node --version
25-
- npm --version
2624
- npm run build
2725
- npm run build:test
2826
- npm run lint
2927
- npm run test
28+
- npm run release

electron/src/services/uhk-device.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ export class UhkDeviceService implements OnDestroy {
9797
if (process.platform !== 'win32' && usbInterface.isKernelDriverActive()) {
9898
usbInterface.detachKernelDriver();
9999
}
100-
usbInterface.claim();
100+
101+
// https://github.com/tessel/node-usb/issues/30
102+
// Mac not allow detach the USB driver from the kernel
103+
if (process.platform !== 'darwin') {
104+
usbInterface.claim();
105+
}
106+
101107
this.messageIn$ = Observable.create((subscriber: Subscriber<Buffer>) => {
102108
const inEndPoint: InEndpoint = <InEndpoint>usbInterface.endpoints[0];
103109
console.log('Try to read');

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "uhk-agent",
3+
"main": "electron/dist/electron-main.js",
34
"version": "1.0.0-alpha.1",
45
"description": "Agent is the configuration application of the Ultimate Hacking Keyboard.",
56
"repository": {
@@ -23,6 +24,7 @@
2324
"angular2-template-loader": "0.6.2",
2425
"copy-webpack-plugin": "^4.0.1",
2526
"electron": "1.6.5",
27+
"electron-builder": "^18.3.0",
2628
"electron-rebuild": "^1.5.7",
2729
"expose-loader": "^0.7.1",
2830
"html-loader": "0.4.5",
@@ -31,6 +33,7 @@
3133
"path": "^0.12.7",
3234
"raw-loader": "^0.5.1",
3335
"sass-loader": "^6.0.3",
36+
"standard-version": "^4.0.0",
3437
"stylelint": "^7.10.1",
3538
"ts-loader": "^2.0.3",
3639
"tslint": "~5.1.0",
@@ -85,6 +88,8 @@
8588
"server:web": "webpack-dev-server --config \"web/src/webpack.config.js\" --content-base \"./web/dist\"",
8689
"server:electron": "webpack --config \"electron/src/webpack.config.js\" --watch",
8790
"electron": "electron electron/dist/electron-main.js",
88-
"symlink": "node ./tools/symlinker"
91+
"symlink": "node ./tools/symlinker",
92+
"pack": "node ./scripts/release.js",
93+
"release": "node ./scripts/release.js"
8994
}
9095
}

scripts/release.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
'use strict';
2+
3+
const TEST_BUILD = true; // set true if you would like to test on your local machince
4+
5+
if (!process.env.CI && !TEST_BUILD) {
6+
console.error('Create release only on CI server')
7+
process.exit(1)
8+
}
9+
10+
let branchName = ''
11+
let pullRequestNr = ''
12+
let gitTag = ''
13+
let repoName = ''
14+
15+
if (process.env.TRAVIS) {
16+
branchName = process.env.TRAVIS_BRANCH
17+
pullRequestNr = process.env.TRAVIS_PULL_REQUEST
18+
gitTag = process.env.TRAVIS_TAG
19+
repoName = process.env.TRAVIS_REPO_SLUG
20+
} else if (process.env.APPVEYOR) {
21+
branchName = process.env.APPVEYOR_REPO_BRANCH
22+
pullRequestNr = process.env.APPVEYOR_PULL_REQUEST_NUMBER
23+
gitTag = process.env.APPVEYOR_REPO_TAG_NAME
24+
repoName = process.env.APPVEYOR_REPO_NAME
25+
}
26+
27+
console.log({ branchName, pullRequestNr, gitTag, repoName })
28+
29+
// TODO(Robi): Remove the comment after success tests
30+
const isReleaseCommit = TEST_BUILD || branchName === gitTag //&& repoName === 'ert78gb/electron-playground'
31+
32+
if (!isReleaseCommit) {
33+
console.log('It is not a release task. Skipping publish.')
34+
process.exit(0)
35+
}
36+
37+
38+
const fs = require('fs-extra')
39+
const cp = require('child_process')
40+
const path = require('path')
41+
const builder = require("electron-builder")
42+
const Platform = builder.Platform
43+
44+
let sha = ''
45+
if (process.env.TRAVIS) {
46+
sha = process.env.TRAVIS_COMMIT
47+
} else if (process.env.APPVEYOR) {
48+
sha = process.env.APPVEYOR_REPO_COMMIT
49+
}
50+
51+
let target = ''
52+
53+
if (process.platform === 'darwin') {
54+
target = Platform.MAC.createTarget()
55+
} else if (process.platform === 'win32') {
56+
target = Platform.WINDOWS.createTarget()
57+
} else if (process.platform === 'linux') {
58+
target = Platform.LINUX.createTarget()
59+
} else {
60+
console.error(`I dunno how to publish a release for ${process.platform} :(`)
61+
process.exit(1)
62+
}
63+
64+
if (process.platform === 'darwin') {
65+
// TODO: Remove comment when macOS certificates boughted and exported
66+
//require('./setup-macos-keychain').registerKeyChain()
67+
}
68+
69+
let version = ''
70+
if (TEST_BUILD || gitTag) {
71+
version = gitTag
72+
73+
builder.build({
74+
dir: true,
75+
targets: target,
76+
appMetadata: {
77+
main: 'electron/dist/electron-main.js',
78+
name: 'UHK Agent',
79+
author: {
80+
name: 'Ultimate Gaget Laboratories'
81+
},
82+
},
83+
config: {
84+
appId: 'com.ultimategadgetlabs.uhk.agent',
85+
productName: 'UHK Agent',
86+
mac: {
87+
category: 'public.app-category.utilities',
88+
},
89+
publish: 'github',
90+
files: [
91+
'!**/*',
92+
'electron/dist/**/*',
93+
'node_modules/**/*'
94+
]
95+
96+
},
97+
})
98+
.then(() => {
99+
console.log('Packing success.')
100+
})
101+
.catch((error) => {
102+
console.error(`${error}`)
103+
process.exit(1)
104+
})
105+
}
106+
else {
107+
console.log('No git tag')
108+
// TODO: Need it?
109+
version = sha.substr(0, 8)
110+
process.exit(1)
111+
}

scripts/setup-macos-keychain.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const cp = require('child_process')
4+
const path = require('path')
5+
6+
function registerKeyChain() {
7+
const encryptedFile = path.join(__dirname, '../certs/developer-id-cert.p12.enc')
8+
const decryptedFile = path.join(__dirname, '../certs/developer-id-cert.p12')
9+
cp.execSync(`openssl aes-256-cbc -K $encrypted_04061b49eb95_key -iv $encrypted_04061b49eb95_iv -in ${encryptedFile} -out ${decryptedFile} -d`)
10+
11+
const keyChain = 'mac-build.keychain'
12+
cp.execSync(`security create-keychain -p travis ${keyChain}`)
13+
cp.execSync(`security default-keychain -s ${keyChain}`)
14+
cp.execSync(`security unlock-keychain -p travis ${keyChain}`)
15+
cp.execSync(`security set-keychain-settings -t 3600 -u ${keyChain}`)
16+
17+
cp.execSync(`security import ${decryptedFile} -k ${keyChain} -P $KEY_PASSWORD -T /usr/bin/codesign`)
18+
}
19+
20+
module.exports.registerKeyChain = registerKeyChain

0 commit comments

Comments
 (0)