Skip to content

Commit

Permalink
🔥lançamento
Browse files Browse the repository at this point in the history
  • Loading branch information
saulotarsobc committed Jan 24, 2024
1 parent b8a667c commit 0aa9c6f
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 134 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: launch-app

on:
push:
branches:
- master

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
build-windows:
runs-on: [windows-latest]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm install

- name: Build Electron App
run: npm run dist

- name: Release Electron App
run: npm run release
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# SC - Virtual Screens

![Alt text](images/image.png)

## Use

```sh
git clone https://github.com/saulotarsobc/sc-virtual-screens.git;
cd sc-virtual-screens;
npm install;
npm start;
npm run dev;
```

### NPM Commands
Expand Down
76 changes: 43 additions & 33 deletions backend/index.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,64 @@
// Native
import { join } from "path";
import { format } from "url";
import { exec } from "child_process";

// Packages
import prepareNext from "electron-next";

// Modules
import { BrowserWindow, app, ipcMain, IpcMainEvent, dialog } from "electron";
import { getWinSettings, setWinSettings } from "./store";
import { BrowserWindow, app, ipcMain, IpcMainEvent } from "electron";
// import { getWinSettings, setWinSettings } from "./store";

const isDev = process.argv.some((str) => str == "--dev");
const isStart = process.argv.some((str) => str == "--start");

const UTILS_PATH =
isStart || isDev
? join(__dirname, "..", "utils")
: join(__dirname, "..", "..", "utils");

const URL =
isStart || isDev
? `http://localhost:8000/`
: format({
pathname: join(__dirname, "../frontend/out/index.html"),
protocol: "file:",
slashes: true,
});

const createWindow = () => {
const winSize = getWinSettings();
// const winSize = getWinSettings();

const mainWindow = new BrowserWindow({
height: winSize.h,
width: winSize.w,
minHeight: 500,
minWidth: 400,
// height: winSize.h,
// width: winSize.w,
// minHeight: 500,
// minWidth: 400,

height: 500,
width: 400,
resizable: false,

webPreferences: {
spellcheck: false,
nodeIntegration: false,
contextIsolation: false,
preload: join(__dirname, "preload.js"),
},
});

mainWindow.on("resize", () => {
setWinSettings(mainWindow.getSize());
});
// mainWindow.on("resize", () => {
// setWinSettings(mainWindow.getSize());
// });

mainWindow.setMenu(null);

// open devtools
// abre o devtools se estiver em modo de desenvolvimento
if (isDev) mainWindow.webContents.openDevTools();

mainWindow.loadURL(
isStart || isDev
? `http://localhost:8000/`
: format({
pathname: join(__dirname, "../frontend/out/index.html"),
protocol: "file:",
slashes: true,
})
);
mainWindow.loadURL(URL);
};

// Prepare the frontend once the app is ready
Expand All @@ -60,18 +73,15 @@ app.on("ready", async () => {
app.on("window-all-closed", app.quit);

/* ++++++++++ code ++++++++++ */
ipcMain.on("chooseFiles", (event: IpcMainEvent) => {
dialog
.showOpenDialog({ properties: ["openFile", "multiSelections"] })
.then((result: any) => {
event.returnValue = result;
})
.catch((err: Error) => {
event.returnValue = err.message;
});
});

ipcMain.on("createUser", (event: IpcMainEvent, data: {}) => {
console.log(data);
event.returnValue = "ok";
ipcMain.on("runCommand", (event: IpcMainEvent, command: string) => {
exec(command, { cwd: UTILS_PATH }, (error, stdout, stderr) => {
if (error) {
console.error(`Erro ao executar o comando: ${error}`);
event.returnValue = { error: true, message: error.message, stderr };
}
event.returnValue = {
error: false,
stdout,
};
});
});
16 changes: 5 additions & 11 deletions backend/preload.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
/* eslint-disable @typescript-eslint/no-namespace */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { IpcRenderer, ipcRenderer } from "electron";
import { ipcRenderer } from "electron";

declare global {
namespace NodeJS {
interface Global {
IpcRenderer: IpcRenderer
API: any;
}
}
}

const db = {
createUser: (data: {}) => ipcRenderer.sendSync("createUser", data),
}

const sys = {
chooseFiles: () => ipcRenderer.sendSync("chooseFiles"),
}

process.once("loaded", () => {
(global as any).api = { ipcRenderer, db, sys };
(global as any).api = {
ipcRenderer,
runCommand: (command: {}) => ipcRenderer.sendSync("runCommand", command),
};
});
Binary file modified build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions frontend/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import Link from "next/link";
import React from "react";

export default function Header() {
const links = [
{ content: "Home", href: "/" },
{ content: "Página 2", href: "/page2" },
];
const links = [{ content: "Home", href: "/" }];

return (
<header>
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Layout({ children }: { children: ReactNode }) {
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="../../build/icon.png" />
</Head>
<Header />
{/* <Header /> */}
{children}
</>
);
Expand Down
59 changes: 46 additions & 13 deletions frontend/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
import { useState } from "react";

export default function Index() {
const [Users, setUsers] = useState([]);
const [data, setData] = useState("");

return (
<main>
<h1>Home</h1>
<main className="flex flex-col p-1">
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded m-1"
onClick={async () => {
const data = await global.api.runCommand(
"deviceinstaller64 install usbmmidd.inf usbmmidd"
);
setData(data);
}}
>
Instalar app
</button>

<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded m-1"
onClick={async () => {
const data = await global.api.runCommand(
"deviceinstaller64 stop usbmmidd; deviceinstaller64 remove usbmmidd"
);
setData(data);
}}
>
Remover app
</button>

<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded m-1"
onClick={async () => {
const data = await global.api.runCommand(
"deviceinstaller64 enableidd 1"
);
setData(data);
}}
>
Adicionar tela
</button>

<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded m-1"
onClick={async () => {
const data = await global.api.db.createUser({
firstName: "Saulo",
lastName: "Costa",
});
setUsers(data);
const data = await global.api.runCommand(
"deviceinstaller64 enableidd 0"
);
setData(data);
}}
>
Criar user
Remover tela
</button>

<hr />
<pre className="bg-slate-500">{JSON.stringify(Users, null, 4)}</pre>
<hr />
<pre className="p-5 border border-red-100 rounded-md">
{JSON.stringify(data, null, 4)}
</pre>
</main>
);
}
31 changes: 0 additions & 31 deletions frontend/pages/page2.tsx

This file was deleted.

Binary file added images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"publish": "electron-builder --win -p always",
"publish-linux": "electron-builder --linux -p always",
"postinstall": "electron-builder install-app-deps",
"release": "electron-builder",
"libs-update": "ncu -i"
"release": "electron-builder --win --x64"
},
"dependencies": {
"electron-next": "^3.1.5",
Expand All @@ -44,10 +43,9 @@
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"autoprefixer": "^10.4.16",
"electron": "^28.1.4",
"electron": "^26.6.7",
"electron-builder": "^24.9.1",
"next": "^14.0.4",
"npm-check-updates": "^16.14.12",
"postcss": "^8.4.33",
"rimraf": "^5.0.5",
"tailwindcss": "^3.4.1",
Expand All @@ -72,8 +70,7 @@
"asar": true,
"files": [
"main",
"frontend/out",
"utils"
"frontend/out"
],
"extraResources": [
{
Expand Down
34 changes: 0 additions & 34 deletions utils/Comando para instalação.txt

This file was deleted.

Loading

0 comments on commit 0aa9c6f

Please sign in to comment.