Switch electron.js to typescript
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@ node_modules
|
||||
backend/coverage
|
||||
backend/.nyc_output
|
||||
build
|
||||
/dist
|
||||
.DS_Store
|
||||
test.dot
|
||||
test.png
|
||||
|
||||
@@ -1,49 +1,53 @@
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const { autoUpdater } = require("electron-updater")
|
||||
const log = require('electron-log');
|
||||
const { ConnectionManager, updateNotifier } = require('./backend/build/backend/src/index.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
require('electron-debug')({enabled: process.argv[2] === '--debug'});
|
||||
import { UpdateInfo } from './events'
|
||||
import { BrowserWindow, app } from 'electron'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
autoUpdater.logger = log;
|
||||
autoUpdater.logger.transports.file.level = 'info';
|
||||
log.info('App starting...');
|
||||
const { autoUpdater } = require('electron-updater')
|
||||
const log = require('electron-log')
|
||||
import { ConnectionManager, updateNotifier } from './backend/src/index'
|
||||
|
||||
const isDebugEnabled = Boolean(process.argv.find(arg => arg === 'debug'))
|
||||
require('electron-debug')({ enabled: isDebugEnabled })
|
||||
|
||||
autoUpdater.logger = log
|
||||
autoUpdater.logger.transports.file.level = 'info'
|
||||
log.info('App starting...')
|
||||
|
||||
const connectionManager = new ConnectionManager()
|
||||
connectionManager.manageConnections()
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow
|
||||
let mainWindow: BrowserWindow | undefined
|
||||
|
||||
function createWindow () {
|
||||
const icon = path.join(__dirname, 'icon.png')
|
||||
function createWindow() {
|
||||
const iconPath = path.join(__dirname, 'icon.png')
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1024,
|
||||
height: 700,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
},
|
||||
icon
|
||||
icon: iconPath,
|
||||
})
|
||||
|
||||
console.log(icon)
|
||||
console.log(iconPath)
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadFile('app/index.html')
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('close', function () {
|
||||
mainWindow.on('close', () => {
|
||||
connectionManager.closeAllConnections()
|
||||
})
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', function () {
|
||||
mainWindow.on('closed', () => {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null
|
||||
mainWindow = undefined
|
||||
app.quit()
|
||||
})
|
||||
}
|
||||
@@ -54,8 +58,8 @@ function createWindow () {
|
||||
app.on('ready', () => {
|
||||
createWindow()
|
||||
|
||||
let updateInfo
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
let updateInfo: UpdateInfo
|
||||
autoUpdater.on('update-available', (info: UpdateInfo) => {
|
||||
console.log('there is an update')
|
||||
updateInfo = info
|
||||
})
|
||||
@@ -78,7 +82,7 @@ app.on('ready', () => {
|
||||
})
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function () {
|
||||
app.on('window-all-closed', () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
@@ -86,7 +90,7 @@ app.on('window-all-closed', function () {
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', function () {
|
||||
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 (mainWindow === null) {
|
||||
@@ -2,12 +2,12 @@
|
||||
"name": "MQTT-Explorer",
|
||||
"version": "0.0.7",
|
||||
"description": "Explore your message queues",
|
||||
"main": "electron.js",
|
||||
"main": "dist/electron.js",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"install": "cd app; npm install; cd ..",
|
||||
"test": "npm run test-backend",
|
||||
"build": "cd app; npm run build; cd ..; cd backend; npm run build; cd ..",
|
||||
"build": "tsc && cd app && npm run build && cd ..",
|
||||
"test-backend": "cd backend && npm run test && cd ..",
|
||||
"prepare-release": "./prepare-release.sh",
|
||||
"package": "ts-node package.ts",
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "./build",
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"lib": ["es2017"],
|
||||
"lib": ["es2017", "dom"],
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"include": ["electron.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user