From a62223211a53db7ded2937a47d7fe0430bb8cec3 Mon Sep 17 00:00:00 2001 From: Dani Date: Thu, 24 Nov 2022 15:39:17 -0800 Subject: [PATCH] Setsuzoku 0.2: Make project build-ready and correct package.json --- .gitignore | 1 + electron-builder.yml | 5 +- main/nextron/background.old.js | 34 ----------- main/nextron/helpers/create-window.js | 86 --------------------------- main/nextron/helpers/index.js | 5 -- main/nextron/preload.js | 7 --- nextron.config.js | 9 --- package.json | 10 ++-- renderer/pages/connect/[...host].jsx | 25 ++++---- renderer/styles/globals.css | 2 + renderer/tailwind.config.js | 2 +- 11 files changed, 25 insertions(+), 161 deletions(-) delete mode 100644 main/nextron/background.old.js delete mode 100644 main/nextron/helpers/create-window.js delete mode 100644 main/nextron/helpers/index.js delete mode 100644 main/nextron/preload.js delete mode 100644 nextron.config.js diff --git a/.gitignore b/.gitignore index c0fc7a9..961bb4b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .next app dist +renderer/out \ No newline at end of file diff --git a/electron-builder.yml b/electron-builder.yml index 89b8be5..7648ba2 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -7,6 +7,7 @@ directories: files: - from: . filter: - - package.json - - app + - main + - renderer + publish: null diff --git a/main/nextron/background.old.js b/main/nextron/background.old.js deleted file mode 100644 index d79bb8f..0000000 --- a/main/nextron/background.old.js +++ /dev/null @@ -1,34 +0,0 @@ -import { app } from 'electron'; -import serve from 'electron-serve'; -import { createWindow } from './helpers'; - -const isProd = process.env.NODE_ENV === 'production'; - -if (isProd) { - serve({ directory: 'app' }); -} else { - app.setPath('userData', `${app.getPath('userData')} (development)`); -}; - -(async () => { - await app.whenReady(); - - const mainWindow = createWindow('main', { - width: 900, - height: 600, - minWidth: 900, - minHeight: 800, - }); - - if (isProd) { - await mainWindow.loadURL('app://./index.html'); - } else { - const port = process.argv[2]; - await mainWindow.loadURL(`http://localhost:${port}/`); - //mainWindow.webContents.openDevTools({ mode: "undocked" }); - } -})(); - -app.on('window-all-closed', () => { - app.quit(); -}); diff --git a/main/nextron/helpers/create-window.js b/main/nextron/helpers/create-window.js deleted file mode 100644 index d79762a..0000000 --- a/main/nextron/helpers/create-window.js +++ /dev/null @@ -1,86 +0,0 @@ -import path from 'path'; -import { - screen, - BrowserWindow, -} from 'electron'; -import Store from 'electron-store'; - -export default function createWindow(windowName, options) { - const key = 'window-state'; - const name = `window-state-${windowName}`; - const store = new Store({ name }); - const defaultSize = { - width: options.width, - height: options.height, - minWidth: options.minWidth, - minHeight: options.minHeight, - }; - let state = {}; - let win; - - const restore = () => store.get(key, defaultSize); - - const getCurrentPosition = () => { - const position = win.getPosition(); - const size = win.getSize(); - return { - x: position[0], - y: position[1], - width: size[0], - height: size[1], - }; - }; - - const windowWithinBounds = (windowState, bounds) => { - return ( - windowState.x >= bounds.x && - windowState.y >= bounds.y && - windowState.x + windowState.width <= bounds.x + bounds.width && - windowState.y + windowState.height <= bounds.y + bounds.height - ); - }; - - const resetToDefaults = () => { - const bounds = screen.getPrimaryDisplay().bounds; - return Object.assign({}, defaultSize, { - x: (bounds.width - defaultSize.width) / 2, - y: (bounds.height - defaultSize.height) / 2 - }); - }; - - const ensureVisibleOnSomeDisplay = (windowState) => { - const visible = screen.getAllDisplays().some(display => { - return windowWithinBounds(windowState, display.bounds) - }); - if (!visible) { - // Window is partially or fully not visible now. - // Reset it to safe defaults. - return resetToDefaults(); - } - return windowState; - }; - - const saveState = () => { - if (!win.isMinimized() && !win.isMaximized()) { - Object.assign(state, getCurrentPosition()); - } - store.set(key, state); - }; - - state = ensureVisibleOnSomeDisplay(restore()); - - win = new BrowserWindow({ - ...options, - ...state, - webPreferences: { - preload: path.join(__dirname, 'preload.js'), - nodeIntegration: false, - contextIsolation: true, - ...options.webPreferences, - }, - }); - - win.on('close', saveState); - - return win; -}; diff --git a/main/nextron/helpers/index.js b/main/nextron/helpers/index.js deleted file mode 100644 index da26903..0000000 --- a/main/nextron/helpers/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import createWindow from './create-window'; - -export { - createWindow, -}; diff --git a/main/nextron/preload.js b/main/nextron/preload.js deleted file mode 100644 index 31c6481..0000000 --- a/main/nextron/preload.js +++ /dev/null @@ -1,7 +0,0 @@ -import { contextBridge } from "electron"; - -contextBridge.exposeInMainWorld("electron", { - test: () => { - console.log("test"); - } -}); \ No newline at end of file diff --git a/nextron.config.js b/nextron.config.js deleted file mode 100644 index e8e4bdb..0000000 --- a/nextron.config.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - webpack: (defaultConfig, env) => - Object.assign(defaultConfig, { - entry: { - background: './main/background.js', - preload: './main/preload.js', - }, - }), -}; \ No newline at end of file diff --git a/package.json b/package.json index e617fe0..baac161 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "private": true, + "private": false, "name": "setsuzoku", - "description": "My application description", + "description": "A simplistic SSH host manager for Windows. Built with Next.js, Electron, and powered by OpenSSH.", "version": "0.1.0", - "author": "Yoshihide Shiono ", + "author": "Dani ", "main": "main/index.js", "scripts": { "clean": "rimraf dist renderer/.next renderer/out", @@ -11,9 +11,7 @@ "build": "next build renderer && next export renderer", "pack-app": "npm run build && electron-builder --dir", "dist": "npm run build && electron-builder", - "dev:nextron": "nextron", - "build:nextron": "nextron build", - "postinstall:nextron": "electron-builder install-app-deps" + "postinstall": "electron-builder install-app-deps" }, "dependencies": { "@next/font": "^13.0.4", diff --git a/renderer/pages/connect/[...host].jsx b/renderer/pages/connect/[...host].jsx index b8187c2..e6ee0ff 100644 --- a/renderer/pages/connect/[...host].jsx +++ b/renderer/pages/connect/[...host].jsx @@ -8,18 +8,21 @@ export default function Connected(props) { const [ status, setStatus ] = useState("connecting"); const [ displayName, setDisplayName ] = useState(null); useEffect(() => { - if (props.host !== null) window.setsuzoku.listing.connect(props.host); + if (router.isReady) { + if (router?.query?.host !== null) window.setsuzoku.listing.connect(router?.query?.host); + else router.push("/"); - window.onmessage = (event) => { - // event.source === window means the message is coming from the preload - // script, as opposed to from an