diff --git a/[fix] forge.config.js b/[fix] forge.config.js index 1eb1710..61fed0e 100644 --- a/[fix] forge.config.js +++ b/[fix] forge.config.js @@ -1,9 +1,3 @@ module.exports = { - packagerConfig: {}, - rebuildConfig: {}, - makers: [ - { - name: '@electron-forge/maker-zip' - } - ] + makers: [{name: '@electron-forge/maker-zip'}] }; diff --git a/[fix] pacakge-json b/[fix] pacakge-json index d9dd57b..832d046 100644 --- a/[fix] pacakge-json +++ b/[fix] pacakge-json @@ -4,35 +4,24 @@ "version": "1.0.0", "description": "My Electron application description", "main": "src/index.js", - "scripts": { - "start": "electron-forge start", - "make": "electron-forge make" - }, - "keywords": [], "author": { "name": "jhk0530", "email": "hwanistic@gmail.com" }, "license": "MIT", - "repository": { + "repository": { "type": "git", "url": "https://github.com/zarathucorp/shiny-electron-template-m1" }, "dependencies": { "axios": "0.27.2", - "electron-squirrel-startup": "^1.0.0", "esm": "^3.2.25", "execa": "^5.1.1" }, "devDependencies": { - "@babel/core": "^7.22.20", - "@babel/plugin-transform-async-to-generator": "^7.22.5", - "@babel/preset-env": "^7.22.20", - "@babel/preset-react": "^7.22.15", "@electron-forge/cli": "^7.2.0", "@electron-forge/maker-zip": "^7.2.0", - "@electron-forge/plugin-auto-unpack-natives": "^7.2.0", - "electron": "^26.2.1", - "fs-extra": "^11.1.1" + "electron": "^26.6.7", + "fs-extra": "^11.2.0" } } diff --git a/src/helpers.js b/src/helpers.js deleted file mode 100644 index 28574dc..0000000 --- a/src/helpers.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2018 Dirk Schumacher, Noam Ross, Rich FitzJohn - -const randomInt = (min, max) => { - return Math.round(Math.random() * ((max + 1) - min) + min) -} - -export const randomPort = () => { - // Those forbidden ports are in line with shiny - // https://github.com/rstudio/shiny/blob/288039162086e183a89523ac0aacab824ef7f016/R/server.R#L734 - const forbiddenPorts = [3659, 4045, 6000, 6665, 6666, 6667, 6668, 6669, 6697]; - while (true) { - let port = randomInt(3000, 8000) - if (forbiddenPorts.includes(port)) - continue - return port - } -} - -export const waitFor = (milliseconds) => { - return new Promise((resolve, _reject) => { - setTimeout(resolve, milliseconds); - }) -} - -export const getRPath = (platform) => { - if (platform === 'win32') { - return 'r-win' - } else if (platform === 'darwin') { - return 'r-mac' - } else if (platform === 'linux') { - return 'r-linux' - } else { - throw new Error('OS not supported') - } -} diff --git a/src/loading.css b/src/loading.css index 27a20c2..7ed1902 100644 --- a/src/loading.css +++ b/src/loading.css @@ -18,13 +18,13 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - .spinner { - margin: 100px auto; - width: 50px; - height: 40px; - text-align: center; - font-size: 10px; - } +.spinner { + margin: 100px auto; + width: 50px; + height: 40px; + text-align: center; + font-size: 10px; +} .spinner > div { background-color: white; @@ -72,8 +72,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } #status { -text-align: center; -color: white; -font-size: 10px; -font-family: Arial,Helvetica Neue,Helvetica,sans-serif; + text-align: center; + color: white; + font-size: 10px; + font-family: Arial,Helvetica Neue,Helvetica,sans-serif; } \ No newline at end of file diff --git a/src/main.js b/src/main.js index 6a40f8a..b68a9dc 100644 --- a/src/main.js +++ b/src/main.js @@ -6,33 +6,47 @@ import { BrowserWindow } from 'electron' -import path from 'path' -import http from 'axios' -import os from 'os' -import execa from 'execa' -import { - randomPort, - waitFor, - getRPath -} from './helpers' - -const rPath = getRPath(os.platform()) +import path from 'path'; +import http from 'axios'; +import os from 'os'; +import execa from 'execa'; -let shutdown = false; +// Helpers -const rpath = path.join(app.getAppPath(), rPath) -const libPath = path.join(rpath, 'library') -const rscript = path.join(rpath, 'bin', 'R') -const shinyAppPath = path.join(app.getAppPath(), 'shiny') +const rPath = 'r-mac'; -const backgroundColor = '#2c3e50'; +const randomPort = (exclude) => { + let min = 3000; + let max = 8000; + let randomInt = Math.floor(Math.random() * (max - min + 1)) + min; + while (exclude.includes(randomInt)) { + randomInt = Math.floor(Math.random() * (max - min + 1)) + min; + } + return randomInt; +} -let rShinyProcess = null; +let shinyPort = randomPort( + [3659, 4045, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669, 6697] +); +// forbiden ports at 2024-01-28 +// https://chromium.googlesource.com/chromium/src.git/+/refs/heads/master/net/base/port_util.cc -if (require('electron-squirrel-startup')) { // eslint-disable-line global-require - app.quit() +const waitFor = (milliseconds) => { + return new Promise((resolve, _reject) => { + setTimeout(resolve, milliseconds); + }) } +const rpath = path.join(app.getAppPath(), rPath); +const libPath = path.join(rpath, 'library'); +const rscript = path.join(rpath, 'bin', 'R'); +const shinyAppPath = path.join(app.getAppPath(), 'shiny'); + +const backgroundColor = '#2c3e50'; // electron + +let shutdown = false; +let rShinyProcess = null; + const tryStartWebserver = async (attempt, progressCallback, onErrorStartup, onErrorLater, onSuccess) => { if (attempt > 100) { await progressCallback({attempt: attempt, code: 'failed'}) @@ -45,8 +59,6 @@ const tryStartWebserver = async (attempt, progressCallback, onErrorStartup, onEr return } - let shinyPort = randomPort() - await progressCallback({attempt: attempt, code: 'start'}) let shinyRunning = false