From eab9bc5805f274e69ab7ff68decda7cdcd63c0b1 Mon Sep 17 00:00:00 2001 From: hippoz Date: Wed, 27 Oct 2021 03:15:29 +0300 Subject: [PATCH] feat: add "app" system --- public/index.html | 1 + src/appmanager/applications/duckduckgo.js | 11 +++++++++++ src/appmanager/appruntime.js | 12 ++++++++++++ src/appmanager/provider.js | 9 +++++++++ src/components/AppTile.svelte | 15 ++++++++++----- src/components/AppTileGrid.svelte | 3 ++- src/env.js | 8 ++++++++ src/index.js | 8 ++++++-- src/svelte.js | 22 ++-------------------- 9 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 src/appmanager/applications/duckduckgo.js create mode 100644 src/appmanager/appruntime.js create mode 100644 src/appmanager/provider.js create mode 100644 src/env.js diff --git a/public/index.html b/public/index.html index ef4907f..52f17c5 100644 --- a/public/index.html +++ b/public/index.html @@ -2,6 +2,7 @@ + app diff --git a/src/appmanager/applications/duckduckgo.js b/src/appmanager/applications/duckduckgo.js new file mode 100644 index 0000000..e0bda9f --- /dev/null +++ b/src/appmanager/applications/duckduckgo.js @@ -0,0 +1,11 @@ +import { spawnBrowser } from "../appruntime"; + +const app = { + name: "duckduckgo", + component: null, + async open() { + await spawnBrowser("https://duckduckgo.com/"); + } +}; + +export default app; \ No newline at end of file diff --git a/src/appmanager/appruntime.js b/src/appmanager/appruntime.js new file mode 100644 index 0000000..8b36a7e --- /dev/null +++ b/src/appmanager/appruntime.js @@ -0,0 +1,12 @@ +import env from '../env'; + +const { spawn } = require('child_process'); + +export function spawnBrowser(url, params=[]) { + return new Promise((resolve, reject) => { + const browserProcess = spawn(env.browserLaunch.browserBinary, [...env.browserLaunch.params, ...params, url]); + + browserProcess.on("spawn", () => resolve(browserProcess)); + browserProcess.on("error", e => reject(e)); + }); +} \ No newline at end of file diff --git a/src/appmanager/provider.js b/src/appmanager/provider.js new file mode 100644 index 0000000..2a6a44f --- /dev/null +++ b/src/appmanager/provider.js @@ -0,0 +1,9 @@ +import duckduckgo from "./applications/duckduckgo"; + +const provider = { + repository: [ + duckduckgo + ] +}; + +export default provider; \ No newline at end of file diff --git a/src/components/AppTile.svelte b/src/components/AppTile.svelte index a7c9d18..da02834 100644 --- a/src/components/AppTile.svelte +++ b/src/components/AppTile.svelte @@ -1,9 +1,13 @@ - \ No newline at end of file diff --git a/src/env.js b/src/env.js new file mode 100644 index 0000000..f12e64a --- /dev/null +++ b/src/env.js @@ -0,0 +1,8 @@ +const env = { + browserLaunch: { + browserBinary: "chromium", + params: ["-kiosk"] + } +}; + +export default env; \ No newline at end of file diff --git a/src/index.js b/src/index.js index f64715c..c495310 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,18 @@ const { app, BrowserWindow } = require('electron'); +const { session } = require('electron') const path = require('path'); const createWindow = () => { const mainWindow = new BrowserWindow({ width: 800, - height: 600 + height: 600, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + } }); mainWindow.setMenuBarVisibility(false); - mainWindow.loadFile(path.join(__dirname, '../public/index.html')); mainWindow.webContents.openDevTools(); }; diff --git a/src/svelte.js b/src/svelte.js index 4a02c7c..edfc883 100644 --- a/src/svelte.js +++ b/src/svelte.js @@ -1,28 +1,10 @@ import App from './App.svelte'; +import provider from './appmanager/provider'; const app = new App({ target: document.body, props: { - applicationRepository: [ - { - name: "Rodent App" - }, - { - name: "Ratly" - }, - { - name: "deadmau5" - }, - { - name: "deadmau5" - }, - { - name: "deadmau5" - }, - { - name: "deadmau5" - } - ] + applicationRepository: provider.repository } });