summaryrefslogtreecommitdiff
path: root/electron/src/main
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2024-05-01 19:34:25 +0200
committerGitHub <noreply@github.com>2024-05-01 19:34:25 +0200
commit2ee4175437bbfcddf98e5eacba9b019113716ac8 (patch)
treeaff6c7c9adfc27f0f33ab4e14edcf17829dbb282 /electron/src/main
parenteb64c88a8bf9c8fe66c33a5309d28e526b994d25 (diff)
Remove electron entirely (#2859)
Co-authored-by: rejbasket
Diffstat (limited to 'electron/src/main')
-rw-r--r--electron/src/main/index.js112
-rw-r--r--electron/src/main/preload.js7
2 files changed, 0 insertions, 119 deletions
diff --git a/electron/src/main/index.js b/electron/src/main/index.js
deleted file mode 100644
index 356e50fb..00000000
--- a/electron/src/main/index.js
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Authors: see git history
- *
- * Copyright (c) 2010 Authors
- * Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
- *
- */
-
-'use strict'
-
-const path = require('path')
-const fs = require('fs')
-const tmp = require('tmp')
-const url = require('url')
-const { app, BrowserWindow, ipcMain, dialog, shell, Menu} = require('electron')
-// url for printPDF flask server which is used in development and production mode
-
-var port = process.env.FLASKPORT
-const printPdfUrl = `http://127.0.0.1:${port}/`
-
-const isDev = process.env.BABEL_ENV === 'development'
-
-var target = null
-// Finds this url in the argv array and sets to target value
-if (process.argv.includes(printPdfUrl)) {
- target = printPdfUrl
-} else {
- target = process.argv[1] || "";
-}
-var targetURL = url.parse(target)
-var winURL = null
-
-// Eventually this will be migrated to Vue.
-if (targetURL.protocol) {
- winURL = target
-} else {
- winURL = `file://${__dirname}/index.html?${targetURL.query || ""}#${targetURL.pathname || ""}`
-}
-
-function createWindow() {
- const mainWindow = new BrowserWindow({
- useContentSize: true,
- webPreferences: {
- preload: path.join(__dirname, 'preload.js'),
- nodeIntegration: false,
- contextIsolation: true,
- },
- })
- if (isDev) {
- // printPDF in development mode will have dev tools activated
- // Vuejs parts of Ink/Stich will not and dev tools must be accessed though the menu of electron window
- mainWindow.loadURL(winURL)
- mainWindow.webContents.openDevTools()
- } else {
- mainWindow.loadURL(winURL)
- }
- // This will remove the menu from the release, in dev mode the menu is available.
- if(process.platform === "darwin" && !isDev) {
- Menu.setApplicationMenu(Menu.buildFromTemplate([]));
- } if(process.platform === "win32" || process.platform === "linux" && !isDev) {
- mainWindow.removeMenu();
- }
- mainWindow.maximize()
- // save to PDF
- ipcMain.on('save-pdf', (event, pageSize) => {
- const webContents = event.sender
- const win = BrowserWindow.fromWebContents(webContents)
- const saveOpt = {
- title: "Save PDF",
- defaultPath: "Inkstitch.pdf",
- filters: [{ name: 'PDF', extensions: ['pdf'] }],
- bookmark: "true",
- }
- win.webContents.printToPDF({}).then(pageSize => {
- dialog.showSaveDialog(saveOpt).then(filename => {
- const { filePath } = filename;
- fs.writeFileSync(filePath, pageSize, (error) => {
- if (error) {
- throw error
- }
- console.log(`Wrote PDF successfully to ${pdfPath}`)
- })
- }).catch(error => {
- console.log(`Failed to write PDF to ${pdfPath}: `, error)
- })
- })
- })
- // openPDF
- ipcMain.on('open-pdf', (event, pageSize) => {
- const webContents = event.sender
- const win = BrowserWindow.fromWebContents(webContents)
- win.webContents.printToPDF({}).then(pageSize => {
- tmp.file({keep: true, discardDescriptor: true}, function(err, path, fd, cleanupCallback) {
- fs.writeFileSync(path, pageSize, 'utf-8');
- shell.openPath(path);
- })
- })
- })
-}
-
-app.whenReady().then(() => {
- createWindow()
- app.on('activate', () => {
- if(BrowserWindow.getAllWindows().length === 0) {
- createWindow()
- }
- })
-})
-
-app.on('window-all-closed', () => {
- app.quit()
-})
diff --git a/electron/src/main/preload.js b/electron/src/main/preload.js
deleted file mode 100644
index b7d1c02a..00000000
--- a/electron/src/main/preload.js
+++ /dev/null
@@ -1,7 +0,0 @@
-const { contextBridge, ipcRenderer } = require ('electron')
-
-contextBridge.exposeInMainWorld('inkstitchAPI', {
- savepdf: (pageSize) => { ipcRenderer.send('save-pdf', pageSize) },
- openpdf: (pageSize) => { ipcRenderer.send('open-pdf', pageSize) },
- flaskport: () => process.env.FLASKPORT,
-})