Skip to content

Commit

Permalink
fix 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetrom17 committed Jan 9, 2025
1 parent dd848f7 commit 205ad48
Show file tree
Hide file tree
Showing 13 changed files with 1,137 additions and 14,829 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,40 @@
```bash
npm install --global yarn
yarn add electron-builder --dev
npm install
yarn add electron-builder #--dev
yarn install
```
#
# Executar localmente
```bash
npm run start
yarn start
```
# Compilação
- Windows e Linux
- Windows 10/11
```bash
yarn build:win-linux
yarn electron-builder build --win
```
#
```bash
yarn electron-builder build --linux
```
- Mac
```bash
yarn build:mac
yarn electron-builder build --mac
```
Todos:
```bash
yarn electron-builder build -mwl
```
# Atualização
Expand Down
Binary file modified assets/icons/logo.icns
Binary file not shown.
Binary file modified assets/icons/logo.ico
Binary file not shown.
Binary file modified assets/icons/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
408 changes: 395 additions & 13 deletions license

Large diffs are not rendered by default.

Binary file removed logo-test.png
Binary file not shown.
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 47 additions & 46 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
const { app, BrowserWindow, Menu, shell, Tray } = require("electron");
const path = require("path");

let tray = null; // Variável para armazenar a instância da bandeja
let win = null; // Variável para armazenar a instância da janela
let tray = null;
let win = null;

// Função para resolver caminhos absolutos
const resolveAssetPath = (asset) =>
app.isPackaged
? path.join(process.resourcesPath, asset)
: path.join(__dirname, asset);
function resolveAssetPath(asset) {
return app.isPackaged
? path.join(process.resourcesPath, "assets", asset)
: path.join(__dirname, "assets", asset);
}

function createTray() {
const iconPath = resolveAssetPath("icons/logo.ico"); // Alterado para .ico
try {
tray = new Tray(iconPath);
} catch (error) {
console.error("Failed to load tray icon:", error);
return;
}

const contextMenu = Menu.buildFromTemplate([
{
label: 'Abrir',
click: () => win.show()
},
{
label: 'Fechar',
click: () => {
app.isQuiting = true;
app.quit();
}
}
]);

tray.setToolTip('LoFi Radio');
tray.setContextMenu(contextMenu);
tray.on('click', () => win.show());
}

function createWindow() {
win = new BrowserWindow({
width: 400,
height: 400,
icon: resolveAssetPath("icons/logo.ico"), // Alterado para .ico
webPreferences: {
preload: path.join(__dirname, "preload.js"),
contextIsolation: true,
enableRemoteModule: false,
nodeIntegration: false,
},
});

win.loadFile("index.html");
win.loadFile("index.html").catch((err) => {
console.error("Failed to load index.html:", err);
});

// Menu template com um botão personalizado
const menu = Menu.buildFromTemplate([
{
label: "Sobre",
Expand All @@ -45,56 +74,28 @@ function createWindow() {
},
]);

// Definir o menu da aplicação
Menu.setApplicationMenu(menu);

// Evento para minimizar a janela ao fechar
win.on("close", (event) => {
if (!app.isQuiting) {
event.preventDefault();
win.hide();
return false;
}
});
}

app.whenReady().then(() => {
createWindow();
createTray();
});

// Criar a bandeja
tray = new Tray(resolveAssetPath("logo.png")); // Caminho dinâmico para o logo
const contextMenu = Menu.buildFromTemplate([
{
label: "Abrir",
click: () => {
win.show();
},
},
{
label: "Sair",
click: () => {
app.isQuiting = true; // Define a flag para indicar que a aplicação deve sair
app.quit();
},
},
]);

tray.setToolTip("Minha Aplicação Electron");
tray.setContextMenu(contextMenu);

// Evento de clique na bandeja
tray.on("click", () => {
win.isVisible() ? win.hide() : win.show();
});

app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
app.on('before-quit', () => {
app.isQuiting = true;
});

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
});
Loading

0 comments on commit 205ad48

Please sign in to comment.