mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
update: dynamic indexer & electron notify
This commit is contained in:
parent
5e06f2b6d0
commit
9f760011c5
@ -8,15 +8,17 @@ const {
|
|||||||
shell,
|
shell,
|
||||||
screen,
|
screen,
|
||||||
BrowserView,
|
BrowserView,
|
||||||
|
Notification,
|
||||||
globalShortcut
|
globalShortcut
|
||||||
} = require('electron');
|
} = require('electron')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
// const { spawn, exec } = require('child_process');
|
// const { spawn, exec } = require('child_process')
|
||||||
// const { autoUpdater } = require('electron-updater');
|
// const { autoUpdater } = require('electron-updater')
|
||||||
const log = require('electron-log');
|
const log = require('electron-log');
|
||||||
const packagejson = require('../package.json')
|
const packagejson = require('../package.json')
|
||||||
const is = require('electron-is')
|
const is = require('electron-is')
|
||||||
const waitOn = require('wait-on');
|
const waitOn = require('wait-on');
|
||||||
|
const { title } = require('process');
|
||||||
|
|
||||||
let app_path = is.dev()? 'http://127.0.0.1:8000/' : `file://${path.join(__dirname, '..', 'renderer')}/index.html`;
|
let app_path = is.dev()? 'http://127.0.0.1:8000/' : `file://${path.join(__dirname, '..', 'renderer')}/index.html`;
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
@ -24,18 +26,49 @@ let tray;
|
|||||||
let watcher;
|
let watcher;
|
||||||
|
|
||||||
// This gets rid of this: https://github.com/electron/electron/issues/13186
|
// This gets rid of this: https://github.com/electron/electron/issues/13186
|
||||||
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true
|
||||||
// app.commandLine.appendSwitch("disable-web-security");
|
// app.commandLine.appendSwitch("disable-web-security")
|
||||||
app.commandLine.appendSwitch('disable-gpu-vsync=gpu');
|
app.commandLine.appendSwitch('disable-gpu-vsync=gpu')
|
||||||
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors');
|
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors')
|
||||||
|
|
||||||
const gotTheLock = app.requestSingleInstanceLock();
|
const gotTheLock = app.requestSingleInstanceLock()
|
||||||
|
const notifySupport = Notification.isSupported()
|
||||||
|
|
||||||
// Prevent multiple instances
|
// Prevent multiple instances
|
||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notify(params) {
|
||||||
|
if(!notifySupport || !params) return false
|
||||||
|
|
||||||
|
let options = {
|
||||||
|
title: "",
|
||||||
|
body: "",
|
||||||
|
icon: null,
|
||||||
|
timeoutType: "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
const keys = Object.keys(params)
|
||||||
|
const values = Object.values(params)
|
||||||
|
|
||||||
|
for (let index = 0; index < keys.length; index++) {
|
||||||
|
const element = array[index];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
params.forEach(element => {
|
||||||
|
options[element] = element
|
||||||
|
})
|
||||||
|
|
||||||
|
new Notification(options).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function __init() {
|
||||||
|
log.log('Notify support => ', notifySupport)
|
||||||
|
createWindow()
|
||||||
|
}
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
title: packagejson.title,
|
title: packagejson.title,
|
||||||
@ -104,29 +137,29 @@ function createWindow() {
|
|||||||
|
|
||||||
const trayMenuTemplate = [
|
const trayMenuTemplate = [
|
||||||
{
|
{
|
||||||
label: 'Dev Tools',
|
label: '🧰 DevTools',
|
||||||
click: () => mainWindow.webContents.openDevTools()
|
click: () => mainWindow.webContents.openDevTools()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: '🔄 Reload',
|
||||||
click: () => {
|
click: () => {
|
||||||
app.relaunch();
|
app.relaunch();
|
||||||
mainWindow.close();
|
mainWindow.close();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Close app',
|
label: '🛑 Quit',
|
||||||
click: () => mainWindow.close()
|
click: () => mainWindow.close()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const trayMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
tray.setContextMenu(Menu.buildFromTemplate(trayMenuTemplate));
|
||||||
tray.setContextMenu(trayMenu);
|
|
||||||
tray.setToolTip(packagejson.title);
|
tray.setToolTip(packagejson.title);
|
||||||
tray.on('double-click', () => mainWindow.show());
|
tray.on('double-click', () => mainWindow.show());
|
||||||
|
|
||||||
mainWindow.loadURL(app_path);
|
mainWindow.loadURL(app_path);
|
||||||
if (is.dev()) {
|
if (is.dev()) {
|
||||||
|
|
||||||
mainWindow.webContents.openDevTools();
|
mainWindow.webContents.openDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,15 +186,16 @@ app.on('ready', () => {
|
|||||||
backgroundColor: "#00000000",
|
backgroundColor: "#00000000",
|
||||||
});
|
});
|
||||||
loadWindow.loadURL(`file://${__dirname}/statics/loading_dev.html`)
|
loadWindow.loadURL(`file://${__dirname}/statics/loading_dev.html`)
|
||||||
|
notify({title: "Starting development server..."})
|
||||||
waitOn({ resources: [app_path] }, function (err) {
|
waitOn({ resources: [app_path] }, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return log.log(err, ' | electron Aborted create window')
|
return log.log(err, ' | electron Aborted create window')
|
||||||
}
|
}
|
||||||
createWindow()
|
__init()
|
||||||
loadWindow.close()
|
loadWindow.close()
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
createWindow()
|
__init()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -216,3 +250,7 @@ ipcMain.handle('appRestart', () => {
|
|||||||
app.relaunch();
|
app.relaunch();
|
||||||
mainWindow.close();
|
mainWindow.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('app_notify', () => {
|
||||||
|
notify({ title: "Bruh" })
|
||||||
|
})
|
38
src/components/Invalid/index.js
Normal file
38
src/components/Invalid/index.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import * as antd from 'antd'
|
||||||
|
import styles from './index.less'
|
||||||
|
|
||||||
|
const InvalidSkeleton = (props) => {
|
||||||
|
return(
|
||||||
|
<antd.Card className={styles.invalidSkeleton} bordered="false">
|
||||||
|
<antd.Skeleton active />
|
||||||
|
<antd.Result style={{
|
||||||
|
position: "absolute",
|
||||||
|
zIndex: "15",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
padding: "12px 24px"
|
||||||
|
}}>
|
||||||
|
Bruh fail?
|
||||||
|
</antd.Result>
|
||||||
|
</antd.Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default class Invalid extends React.Component{
|
||||||
|
constructor(props){
|
||||||
|
super(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
render(){
|
||||||
|
const Components = {
|
||||||
|
skeleton: <InvalidSkeleton />
|
||||||
|
}
|
||||||
|
const type = this.props.type
|
||||||
|
if (!type) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return Components[type]
|
||||||
|
}
|
||||||
|
}
|
14
src/components/Invalid/index.less
Normal file
14
src/components/Invalid/index.less
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.invalidSkeleton{
|
||||||
|
:global{
|
||||||
|
.ant-card{
|
||||||
|
border-radius: 7px;
|
||||||
|
}
|
||||||
|
.ant-card-body{
|
||||||
|
display: flex;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.ant-skeleton{
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import * as Icons from './Icons'
|
|||||||
import Loader from './Loader/Loader.js'
|
import Loader from './Loader/Loader.js'
|
||||||
import About from './About'
|
import About from './About'
|
||||||
import * as Feather from 'feather-reactjs'
|
import * as Feather from 'feather-reactjs'
|
||||||
|
import Invalid from './Invalid'
|
||||||
|
|
||||||
// App Layout Components
|
// App Layout Components
|
||||||
import * as MyLayout from './Layout/index.js'
|
import * as MyLayout from './Layout/index.js'
|
||||||
@ -18,6 +19,7 @@ import PostCreator from './PostCreator'
|
|||||||
|
|
||||||
// Mix & Export all
|
// Mix & Export all
|
||||||
export {
|
export {
|
||||||
|
Invalid,
|
||||||
Icons,
|
Icons,
|
||||||
Feather,
|
Feather,
|
||||||
About,
|
About,
|
||||||
|
@ -5,7 +5,6 @@ import store from 'store';
|
|||||||
import { i18n, app_config } from 'config';
|
import { i18n, app_config } from 'config';
|
||||||
import * as errorHandlers from 'core/libs/errorhandler'
|
import * as errorHandlers from 'core/libs/errorhandler'
|
||||||
import platform from 'platform'
|
import platform from 'platform'
|
||||||
import { uri_resolver } from 'api/lib';
|
|
||||||
import request from 'request'
|
import request from 'request'
|
||||||
|
|
||||||
const { pathToRegexp } = require('path-to-regexp');
|
const { pathToRegexp } = require('path-to-regexp');
|
||||||
@ -30,6 +29,7 @@ export const app_info = {
|
|||||||
layout: platform.layout
|
layout: platform.layout
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// [Experimental], not in use
|
||||||
export function getGlobals(params, callback) {
|
export function getGlobals(params, callback) {
|
||||||
if (!params || !params.server) return false
|
if (!params || !params.server) return false
|
||||||
let tmpResponse = []
|
let tmpResponse = []
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React from 'react'
|
||||||
import { pathMatchRegexp } from 'core'
|
import { pathMatchRegexp } from 'core'
|
||||||
import Error404 from './404.js'
|
import Error404 from './404.js'
|
||||||
// <UserProfile {...this.props} regx={matchUser} />
|
// <UserProfile {...this.props} regx={matchUser} />
|
||||||
|
import { Invalid } from 'components'
|
||||||
|
|
||||||
class PageIndexer extends PureComponent {
|
class PageIndexer extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
const matchUser = pathMatchRegexp('/@:id', location.pathname)
|
const matchUser = pathMatchRegexp('/@:id', location.pathname)
|
||||||
@ -12,14 +13,14 @@ class PageIndexer extends PureComponent {
|
|||||||
if (matchUser) {
|
if (matchUser) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
User, matched => {matchUser}
|
{matchUser}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (matchSetting) {
|
if (matchSetting) {
|
||||||
return(
|
return(
|
||||||
<div>
|
<div>
|
||||||
Bruh, matched => {matchSetting}
|
<Invalid type="skeleton" />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ const menuMap = {
|
|||||||
<span>
|
<span>
|
||||||
<Icons.Image /> Theme
|
<Icons.Image /> Theme
|
||||||
</span>
|
</span>
|
||||||
),
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Debug extends React.Component {
|
export default class Debug extends React.Component {
|
||||||
|
18
src/pages/test.js
Normal file
18
src/pages/test.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export default class Render extends React.Component {
|
||||||
|
state = {
|
||||||
|
style: { textAlign: "center" }
|
||||||
|
}
|
||||||
|
|
||||||
|
render(){
|
||||||
|
const { style } = this.state
|
||||||
|
const cambiarColor = (color) => { this.setState({ style: { color: color, ...style } }) }
|
||||||
|
return(
|
||||||
|
<div style={style} >
|
||||||
|
Current Style => { JSON.stringify(style) }<br />
|
||||||
|
<button onClick={() => { cambiarColor("green") }} > Update estilo </button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user