mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
electron packaging
This commit is contained in:
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
*~
|
*~
|
||||||
*.log
|
*.log
|
||||||
|
out/
|
||||||
|
.DS_Store
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
module.exports = {
|
||||||
|
packagerConfig: {},
|
||||||
|
rebuildConfig: {},
|
||||||
|
makers: [
|
||||||
|
{
|
||||||
|
name: '@electron-forge/maker-squirrel',
|
||||||
|
config: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '@electron-forge/maker-zip',
|
||||||
|
platforms: ['darwin'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '@electron-forge/maker-deb',
|
||||||
|
config: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '@electron-forge/maker-rpm',
|
||||||
|
config: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
+13
-2
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "sh2",
|
"name": "sh2",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "emain.js",
|
"main": "dist/emain-dev.js",
|
||||||
"license": "Proprietary",
|
"license": "Proprietary",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"autobind-decorator": "^2.4.0",
|
"autobind-decorator": "^2.4.0",
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"dayjs": "^1.11.3",
|
"dayjs": "^1.11.3",
|
||||||
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
"fs-ext": "^2.0.0",
|
"fs-ext": "^2.0.0",
|
||||||
"mobx": "^6.6.0",
|
"mobx": "^6.6.0",
|
||||||
"mobx-react": "^7.5.0",
|
"mobx-react": "^7.5.0",
|
||||||
@@ -17,6 +18,7 @@
|
|||||||
"throttle-debounce": "^5.0.0",
|
"throttle-debounce": "^5.0.0",
|
||||||
"tsx-control-statements": "^4.1.1",
|
"tsx-control-statements": "^4.1.1",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^9.0.0",
|
||||||
|
"winston": "^3.8.2",
|
||||||
"xterm": "^5.0.0"
|
"xterm": "^5.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -28,7 +30,11 @@
|
|||||||
"@babel/preset-env": "^7.18.2",
|
"@babel/preset-env": "^7.18.2",
|
||||||
"@babel/preset-react": "^7.17.12",
|
"@babel/preset-react": "^7.17.12",
|
||||||
"@babel/preset-typescript": "^7.17.12",
|
"@babel/preset-typescript": "^7.17.12",
|
||||||
"@electron-forge/cli": "^6.0.0-beta.64",
|
"@electron-forge/cli": "^6.0.0-beta.70",
|
||||||
|
"@electron-forge/maker-deb": "^6.0.0-beta.70",
|
||||||
|
"@electron-forge/maker-rpm": "^6.0.0-beta.70",
|
||||||
|
"@electron-forge/maker-squirrel": "^6.0.0-beta.70",
|
||||||
|
"@electron-forge/maker-zip": "^6.0.0-beta.70",
|
||||||
"@types/classnames": "^2.3.1",
|
"@types/classnames": "^2.3.1",
|
||||||
"@types/electron": "^1.6.10",
|
"@types/electron": "^1.6.10",
|
||||||
"@types/node": "^18.0.3",
|
"@types/node": "^18.0.3",
|
||||||
@@ -52,5 +58,10 @@
|
|||||||
"webpack-cli": "^4.9.2",
|
"webpack-cli": "^4.9.2",
|
||||||
"webpack-dev-server": "^4.9.1",
|
"webpack-dev-server": "^4.9.1",
|
||||||
"webpack-merge": "^5.8.0"
|
"webpack-merge": "^5.8.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron-forge start",
|
||||||
|
"package": "electron-forge package",
|
||||||
|
"make": "electron-forge make"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ node_modules/.bin/electron-rebuild
|
|||||||
```bash
|
```bash
|
||||||
# @scripthaus command electron
|
# @scripthaus command electron
|
||||||
# @scripthaus cd :playbook
|
# @scripthaus cd :playbook
|
||||||
node_modules/.bin/electron dist/emain-dev.js
|
SH_DEV=1 node_modules/.bin/electron dist/emain-dev.js
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+46
-32
@@ -6,6 +6,34 @@ import * as child_process from "node:child_process";
|
|||||||
import {debounce} from "throttle-debounce";
|
import {debounce} from "throttle-debounce";
|
||||||
import {acquireSCElectronLock} from "./base";
|
import {acquireSCElectronLock} from "./base";
|
||||||
import {handleJsonFetchResponse} from "./util";
|
import {handleJsonFetchResponse} from "./util";
|
||||||
|
import * as winston from "winston";
|
||||||
|
import * as util from "util";
|
||||||
|
import {sprintf} from "sprintf-js";
|
||||||
|
|
||||||
|
let isDev = (process.env.SH_DEV != null);
|
||||||
|
let scHome = getScHomeDir();
|
||||||
|
ensureDir(scHome);
|
||||||
|
|
||||||
|
let logger;
|
||||||
|
let loggerConfig = {
|
||||||
|
level: "info",
|
||||||
|
format: winston.format.combine(
|
||||||
|
winston.format.timestamp({format: "YYYY-MM-DD HH:mm:ss"}),
|
||||||
|
winston.format.printf(info => `${info.timestamp} ${info.message}`),
|
||||||
|
),
|
||||||
|
transports: [
|
||||||
|
new winston.transports.File({filename: path.join(scHome, "scripthaus-app.log"), level: "info"}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
if (isDev) {
|
||||||
|
loggerConfig.transports.push(new winston.transports.Console());
|
||||||
|
}
|
||||||
|
logger = winston.createLogger(loggerConfig);
|
||||||
|
function log(...msg) {
|
||||||
|
logger.info(util.format(...msg));
|
||||||
|
}
|
||||||
|
console.log = log;
|
||||||
|
console.log(sprintf("scripthaus-app starting, SCRIPTHAUS_HOME=%s, dirname=%s", scHome, __dirname));
|
||||||
|
|
||||||
// TODO fix these paths
|
// TODO fix these paths
|
||||||
const LocalServerPath = "/Users/mike/scripthaus/local-server";
|
const LocalServerPath = "/Users/mike/scripthaus/local-server";
|
||||||
@@ -16,6 +44,23 @@ const LocalServerCwd = "/Users/mike/work/gopath/src/github.com/scripthaus-dev/sh
|
|||||||
let localServerProc = null;
|
let localServerProc = null;
|
||||||
let localServerShouldRestart = false;
|
let localServerShouldRestart = false;
|
||||||
|
|
||||||
|
// must match golang
|
||||||
|
function getScHomeDir() {
|
||||||
|
let scHome = process.env.SCRIPTHAUS_HOME;
|
||||||
|
if (scHome == null) {
|
||||||
|
let homeDir = process.env.HOME;
|
||||||
|
if (homeDir == null) {
|
||||||
|
homeDir = "/";
|
||||||
|
}
|
||||||
|
scHome = path.join(homeDir, "scripthaus");
|
||||||
|
}
|
||||||
|
return scHome;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureDir(dir) {
|
||||||
|
fs.mkdirSync(dir, {recursive: true, mode: 0o700});
|
||||||
|
}
|
||||||
|
|
||||||
let app = electron.app;
|
let app = electron.app;
|
||||||
app.setName("ScriptHaus");
|
app.setName("ScriptHaus");
|
||||||
|
|
||||||
@@ -52,7 +97,6 @@ let menu = electron.Menu.buildFromTemplate(menuTemplate);
|
|||||||
electron.Menu.setApplicationMenu(menu);
|
electron.Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
let MainWindow = null;
|
let MainWindow = null;
|
||||||
let RemotesWindow = null;
|
|
||||||
|
|
||||||
function getMods(input : any) {
|
function getMods(input : any) {
|
||||||
return {meta: input.meta, shift: input.shift, ctrl: input.ctrl, alt: input.alt};
|
return {meta: input.meta, shift: input.shift, ctrl: input.ctrl, alt: input.alt};
|
||||||
@@ -61,31 +105,6 @@ function getMods(input : any) {
|
|||||||
function shNavHandler(event : any, url : any) {
|
function shNavHandler(event : any, url : any) {
|
||||||
console.log("navigation", url);
|
console.log("navigation", url);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (url == "file:///remotes.html") {
|
|
||||||
createRemotesWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createRemotesWindow() {
|
|
||||||
if (RemotesWindow != null) {
|
|
||||||
console.log("remotes exists");
|
|
||||||
RemotesWindow.focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log("create remotes window");
|
|
||||||
let win = new electron.BrowserWindow({
|
|
||||||
width: 800,
|
|
||||||
height: 600,
|
|
||||||
webPreferences: {
|
|
||||||
preload: path.join(__dirname, "../src/preload.js"),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
RemotesWindow = win;
|
|
||||||
win.loadFile("../static/remotes.html");
|
|
||||||
win.on("close", () => {
|
|
||||||
RemotesWindow = null;
|
|
||||||
});
|
|
||||||
win.webContents.on("will-navigate", shNavHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMainWindow(clientData) {
|
function createMainWindow(clientData) {
|
||||||
@@ -99,7 +118,7 @@ function createMainWindow(clientData) {
|
|||||||
preload: path.join(__dirname, "../src/preload.js"),
|
preload: path.join(__dirname, "../src/preload.js"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
win.loadFile("../static/index.html");
|
win.loadFile(path.join(__dirname, "../static/index.html"));
|
||||||
win.webContents.on("before-input-event", (e, input) => {
|
win.webContents.on("before-input-event", (e, input) => {
|
||||||
if (input.type != "keyDown") {
|
if (input.type != "keyDown") {
|
||||||
return;
|
return;
|
||||||
@@ -130,11 +149,6 @@ function createMainWindow(clientData) {
|
|||||||
win.webContents.send("w-cmd", mods);
|
win.webContents.send("w-cmd", mods);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//if (input.code == "KeyR" && input.meta && input.alt) {
|
|
||||||
// createRemotesWindow();
|
|
||||||
// e.preventDefault();
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
if (input.code == "KeyH" && input.meta) {
|
if (input.code == "KeyH" && input.meta) {
|
||||||
win.webContents.send("h-cmd", mods);
|
win.webContents.send("h-cmd", mods);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user