Skip to content

Commit

Permalink
Adding some features and solving problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad committed Jun 25, 2020
1 parent 48e0f65 commit 1cde16d
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 47 deletions.
87 changes: 87 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "xmoji",
"version": "0.1.0",
"private": true,
"main": "build/electron.js",
"homepage": "./",
"author": "Forsythe-jones (bagher.codes or Aslemammad)",
"dependencies": {
Expand Down Expand Up @@ -32,17 +33,18 @@
"ts-build": "tsc -p nodeTsconfig.json",
"server": "lite-server -c lite-server.json",
"electron": "npm run electron-build && electron ./build/electron.js",
"dev": "concurrently \"BROWSER=none PORT=5006 yarn start\" \"wait-on http://localhost:5006 && tsc -w -p nodeTsconfig.json\" \"wait-on http://localhost:5006 && ELECTRON_ENV=development electron ./build/electron.js\"",
"dev": "concurrently \"BROWSER=none PORT=5006 yarn start\" \"wait-on http://localhost:5006 && tsc -w -p nodeTsconfig.json\" \"wait-on http://localhost:5006 && nodemon --exec \"\"ELECTRON_ENV=development electron ./build/electron.js\"\" \"",
"preelectron-pack": "yarn build",
"electron-dev": "npm run ts-build && concurrently \"BROWSER=none PORT=5006 yarn start \" \"wait-on http://localhost:5006 && electron ./build/electron.js\"",
"electron-dev": "npm run ts-build && concurrently \"BROWSER=none PORT=5006 yarn start \" \"wait-on http://localhost:5006 && nodemon --exec \"\"electron ./build/electron.js\"\"\"",
"full-build": "npm-run-all build ts-build",
"run": "electron build/electron.js"
},
"build": {
"appId": "com.main.electron-xmoji",
"files": [
"build/**/*",
"node_modules/**/*"
"node_modules/**/*",
"package.json"
],
"directories": {
"buildResources": "assets"
Expand Down Expand Up @@ -79,4 +81,4 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5"
}
}
}
Binary file added public/icon.ico
Binary file not shown.
Binary file added public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Xmoji</title>
</head>

<body>
Expand Down
39 changes: 15 additions & 24 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
"short_name": "Xmoji react app",
"name": "Xmoji",
"icons": [{
"src": "icon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}


],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
2 changes: 0 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';

import logo from './logo.jpg';
import { useGlobalState, useSetGlobaleState } from './Store';

import {
Grid,
Typography,
Expand All @@ -19,7 +18,6 @@ import {
Select,
MenuItem,
} from '@material-ui/core';

const App = () => {
const [state, setState] = [useGlobalState(), useSetGlobaleState()];
const handleCheckbox = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down
53 changes: 40 additions & 13 deletions src/electron.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,85 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { app, BrowserWindow, Menu, globalShortcut } = require('electron');
const { app, BrowserWindow, Menu, globalShortcut, Tray } = require('electron');
const path = require('path');
const robotjs = require('robotjs');
const url = require('url');

const isDev = process.env.ELECTRON_ENV === 'development';
isDev && require('electron-reload')(__dirname);
const createWindow = (emoji: boolean, x: number, y: number) => {
// Create the browser window.
const mainWindow = new BrowserWindow({
let mainWindow = new BrowserWindow({
height: emoji ? 480 : 500, // to check if it is a shortcut
width: emoji ? 450 : 500,
webPreferences: {
// preload : path.join(__dirname, '/js/preload.js')
nodeIntegration: true,
webSecurity: false,
enableRemoteModule: true,
},
resizable: isDev ? true : false,
frame: !emoji ? true : false,
icon: path.join(__dirname, '../build/icon.png'),
});

emoji && mainWindow.setPosition(x, y);

// and load the index.html of the app.
const route = emoji ? '/tab' : '';
const route = emoji ? '#/tab' : '';
mainWindow.loadURL(
isDev ? `http://localhost:5006` + route : `file://${path.join(__dirname, '../build/index.html')}` + route,
isDev ? `http://localhost:5006` + route : `file://${path.join(__dirname, '../build/index.html')}${route}`,
);
route && mainWindow.on('blur', () => mainWindow.close());

// Open the DevTools.
isDev && mainWindow.webContents.openDevTools();
// isDev &&
mainWindow.webContents.openDevTools();

mainWindow.on('closed', () => {
mainWindow = null;
});
};

let appTray;

app.allowRendererProcessReuse = false;

app.on('ready', () => {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open',
click: () => {
createWindow(false, 0, 0);
},
},
{
label: 'Quit',
click: () => {
app.quit();
},
},
]);
appTray = new Tray(`${path.join(__dirname, 'icon.png')}`);
appTray.setContextMenu(contextMenu);

const emojiShortcut = globalShortcut.register('Control+Command+Space', () => {
const mousePosition = robotjs.getMousePos();
createWindow(true, Math.floor(mousePosition.x), Math.floor(mousePosition.y));
});

createWindow(false, 0, 0);

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow(false, 0, 0);
});
Menu.setApplicationMenu(null);
});
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow(false, 0, 0);
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

Expand Down
5 changes: 2 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { HashRouter as Router, Route } from 'react-router-dom';

import './index.css';
import App from './App';
import EmojiTab from './Components/EmojiTab';
import { StateProvider } from './Store';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<StateProvider>
<Router>
<Route exact path="/" component={App} />
<Route exact path="/tab" component={EmojiTab} />
<Route path="/tab" component={EmojiTab} />
</Router>
</StateProvider>,
document.getElementById('root'),
Expand Down

0 comments on commit 1cde16d

Please sign in to comment.