Kaydet (Commit) 7ff53935 authored tarafından Eda Altuntaş's avatar Eda Altuntaş

Deep Linking yerine IPC teknolojisine geçildi

üst 0705aa40
......@@ -3,8 +3,10 @@
import { app, protocol, BrowserWindow } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
const path = require("path");
const isDevelopment = process.env.NODE_ENV !== "production";
let mainWindow;
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } }
......@@ -18,10 +20,11 @@ async function createWindow() {
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
preload: path.join(__dirname, "preload.js")
}
});
mainWindow = win;
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
......@@ -31,7 +34,6 @@ async function createWindow() {
// Load the index.html when not in development
win.loadURL("app://./index.html");
}
require("./deeplink")(app, win, isDevelopment);
}
// Quit when all windows are closed.
......@@ -49,6 +51,19 @@ app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
require("./ipc")();
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
......
import { Deeplink } from "electron-deeplink";
const { exec } = require("child_process");
const handler = (app, mainWindow, isDevelopment) => {
const deeplink = new Deeplink({
app,
mainWindow,
protocol: isDevelopment ? "oyunparki-dev" : "oyunparki"
});
deeplink.on("received", link => {
link = link.split("://")[1].split("/");
const func = link[0],
container = link[1];
if (["viewer", "terminal"].indexOf(func) === -1) {
return;
}
if (func === "terminal") {
if (process.platform === "win32") {
exec(`start cmd.exe /c docker exec -it ${container} sh`);
} else {
exec(`docker exec -it ${container} sh`);
}
}
console.log(func);
console.log(container);
});
};
module.exports = handler;
const { ipcMain } = require("electron");
const { exec } = require("child_process");
const handler = () => {
ipcMain.on("terminal", (_, data) => {
if (process.platform === "win32") {
exec("start", ["cmd", "/c", "docker", "exec", "-it", data, "sh"]);
} else {
exec("exo-open", [
"--launch",
"TerminalEmulator",
"docker",
"exec",
"-it",
data,
"sh"
]);
}
});
ipcMain.on("viewer", (_, data) => {
if (process.platform === "win32") {
exec("virt-viewer", [`spice://localhost:${data}`]);
} else {
exec("remote-viewer", [`spice://localhost:${data}`]);
}
});
};
module.exports = handler;
import { ipcRenderer } from "electron";
window.ipcRenderer = ipcRenderer;
......@@ -44,9 +44,8 @@
}"
>
<a
v-bind:href="
`${$protocol}://viewer/${container.Ports[0].PublicPort}`
"
href="#"
v-on:click="() => f('viewer', container.Ports[0].PublicPort)"
v-if="container.Ports[0]"
>
<icon
......@@ -56,7 +55,7 @@
v-bind:class="$style['icon-border']"
/>
</a>
<a v-bind:href="`${$protocol}://terminal/${container.Id}`">
<a href="#" v-on:click="() => f('terminal', container.Id)">
<icon
icon="terminal"
size="2x"
......@@ -137,6 +136,9 @@ export default {
.finally(() => {
this.getContainers();
});
},
f: function(f, v) {
window.ipcRenderer.send(f, v);
}
}
};
......
......@@ -37,6 +37,9 @@ module.exports = {
fallbackLocale: "tr",
localeDir: "locales",
enableInSFC: false
},
electronBuilder: {
preload: "src/preload.js"
}
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment