Skip to content

Commit

Permalink
feat(electron): add support (#135)
Browse files Browse the repository at this point in the history
* feat(electron): add support
* style(lint): ignore electron/src/node_modules
* chore: git & npm ignore electron/src/{node_modules|package-lock.json}
* chore: add electron to cordova.platforms list in package.json
* chore(electron): bump [email protected]
  • Loading branch information
erisu authored Mar 31, 2022
1 parent 62277d5 commit f6cf8a6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/electron/node_modules
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@ Thumbs.db

node_modules








src/electron/package-lock.json
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.*
tests
src/electron/node_modules
src/electron/package-lock.json
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"id": "cordova-plugin-device",
"platforms": [
"android",
"electron",
"ios",
"windows",
"browser",
Expand All @@ -20,6 +21,7 @@
"device",
"ecosystem:cordova",
"cordova-android",
"cordova-electron",
"cordova-ios",
"cordova-windows",
"cordova-browser",
Expand All @@ -34,7 +36,8 @@
"engines": {
"cordovaDependencies": {
"3.0.0": {
"cordova": ">100"
"cordova": ">100",
"cordova-electron": ">=3.0.0"
}
}
},
Expand Down
9 changes: 9 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git</repo>
<issue>https://issues.apache.org/jira/browse/CB/component/12320648</issue>

<engines>
<engine name="cordova-electron" version=">=3.0.0" />
</engines>

<js-module src="www/device.js" name="device">
<clobbers target="device" />
</js-module>
Expand Down Expand Up @@ -57,6 +61,11 @@
<source-file src="src/ios/CDVDevice.m" />
</platform>

<!-- electron -->
<platform name="electron">
<framework src="src/electron" />
</platform>

<!-- windows -->
<platform name="windows">
<js-module src="src/windows/DeviceProxy.js" name="DeviceProxy">
Expand Down
42 changes: 42 additions & 0 deletions src/electron/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

const { system, osInfo } = require('systeminformation');

module.exports = {
getDeviceInfo: async () => {
try {
const { manufacturer, model, uuid } = await system();
const { platform, distro, codename, build: version } = await osInfo();

return {
manufacturer,
model,
platform: platform === 'darwin' ? codename : distro,
version,
uuid,
isVirtual: false
};
} catch (e) {
console.log(e);
}
}
};
20 changes: 20 additions & 0 deletions src/electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "cordova-plugin-device-electron",
"version": "1.0.0",
"description": "Electron Native Supprot for Cordova Device Plugin",
"main": "index.js",
"keywords": [
"cordova",
"electron",
"device",
"native"
],
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"dependencies": {
"systeminformation": "^5.11.9"
},
"cordova": {
"serviceName": "Device"
}
}

0 comments on commit f6cf8a6

Please sign in to comment.