WIP: Trying to get electron to work.

This commit is contained in:
Aaron Louie 2020-08-31 12:07:40 -04:00
parent 03e8ea921e
commit 06aa652a4e
8 changed files with 9304 additions and 20 deletions

9
.gitignore vendored
View File

@ -399,3 +399,12 @@ Temporary Items
.expo
.expo-shared
# @generated: @expo/electron-adapter@0.0.14
/.expo/*
# Expo Web
/web-build/*
# electron-webpack
/dist
# @end @expo/electron-adapter

3
app.ts Normal file
View File

@ -0,0 +1,3 @@
// temporary workaround for https://github.com/expo/expo-cli/issues/1385
// @ts-ignore
export { default } from './App.tsx';

View File

@ -1,5 +1,6 @@
import React, {ReactElement} from 'react';
import {Button, Text, View} from 'react-native';
// @ts-ignore
import Barcode from 'react-native-barcode-builder';
import {BarCodeProps, ButtonProps, PrintingProps} from '../models/ElementProps';
import {styles} from './Styles';

6
electron-webpack.js Normal file
View File

@ -0,0 +1,6 @@
const { withExpoAdapter } = require('@expo/electron-adapter');
module.exports = withExpoAdapter({
projectRoot: __dirname,
// Provide any overrides for electron-webpack: https://github.com/elecnpm i typescript electron -gtron-userland/electron-webpack/blob/master/docs/en/configuration.md
});

72
electron/main/index.js Normal file
View File

@ -0,0 +1,72 @@
'use strict';
import { BrowserWindow, app } from 'electron';
import * as path from 'path';
import { format as formatUrl } from 'url';
const isDevelopment = process.env.NODE_ENV !== 'production';
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow;
function createMainWindow() {
const browserWindow = new BrowserWindow({ webPreferences: { nodeIntegration: true } });
if (isDevelopment) {
browserWindow.webContents.openDevTools();
}
if (isDevelopment) {
browserWindow.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`);
} else {
browserWindow.loadURL(
formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true,
})
);
}
browserWindow.on('closed', () => {
mainWindow = null;
});
browserWindow.webContents.on('devtools-opened', () => {
browserWindow.focus();
setImmediate(() => {
browserWindow.focus();
});
});
browserWindow.webContents.executeJavaScript(`
navigator.mediaDevices.getUserMedia({video: true})
.then(function(stream) {
console.log('stream', stream);
}).catch(function() {
alert('could not connect stream');
});
`);
return browserWindow;
}
// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow();
}
});
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
});

View File

@ -0,0 +1,5 @@
const { withExpoWebpack } = require('@expo/electron-adapter');
module.exports = config => {
return withExpoWebpack(config);
};

9191
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,19 +5,25 @@
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
"eject": "expo eject",
"customize": "yarn expo-electron customize",
"desktop": "yarn expo-electron start",
"build:desktop": "yarn electron-webpack && yarn electron-builder --dir -c.compression=store -c.mac.identity=null (-c.compression=store"
},
"dependencies": {
"@react-native-community/art": "^1.2.0",
"@expo/electron-adapter": "0.0.14",
"@expo/webpack-config": "^0.12.27",
"electron": "^10.1.0",
"expo": "~38.0.8",
"expo-barcode-scanner": "~8.2.1",
"expo-status-bar": "^1.0.2",
"jsbarcode": "^3.11.0",
"node-hid": "^1.3.0",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
"react-native-barcode-builder": "github:cdesch/react-native-barcode-builder#master",
"react-native-web": "~0.11.7"
"react-native-web": "^0.11.7"
},
"devDependencies": {
"@babel/core": "^7.8.6",
@ -25,5 +31,28 @@
"@types/react-native": "~0.62.13",
"typescript": "~3.9.5"
},
"private": true
"private": true,
"build": {
"extraMetadata": {
"main": "main.js"
},
"files": [
{
"from": "dist/main/",
"to": "./",
"filter": [
"**/*"
]
},
{
"from": "dist/renderer",
"to": "./",
"filter": [
"**/*"
]
},
"package.json",
"**/node_modules/**/*"
]
}
}