Skip to content

Commit

Permalink
First release of the app.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasff committed Apr 18, 2022
1 parent 961a8a5 commit 6ac9563
Show file tree
Hide file tree
Showing 11 changed files with 8,818 additions and 40 deletions.
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
root = true

[*]
indent_style = tab
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
20 changes: 16 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: macos-latest
release:
runs-on: ${{ matrix.os }}

name: Node.js ${{ matrix.node-version }} @ ${{ matrix.node-version }}

strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
node-version:
- 14
steps:
Expand All @@ -17,4 +20,13 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- name: Build/release Electron app
uses: samuelmeuli/action-electron-builder@v1
with:
# GitHub token, automatically provided to the action
# (No need to define this secret in the repo settings)
github_token: ${{ secrets.github_token }}

# If the commit is tagged with a version (e.g. "v1.0.0"),
# release the app after building
release: ${{ startsWith(github.ref, 'refs/tags/v') }}
Binary file removed build/background.png
Binary file not shown.
Binary file removed build/[email protected]
Binary file not shown.
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.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<html>
<head>
<meta charset="utf-8">
<title>Electron boilerplate</title>
<title>Electron</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<header>
<h1>Electron boilerplate</h1>
<h1>Electron</h1>
<p></p>
</header>
<section class="main"></section>
Expand Down
58 changes: 44 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
'use strict';
const path = require('path');
const {app, BrowserWindow, Menu} = require('electron');
const {app, BrowserWindow, Menu, protocol, shell} = require('electron');
/// const {autoUpdater} = require('electron-updater');
const {is} = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const contextMenu = require('electron-context-menu');
const config = require('./config.js');
const menu = require('./menu.js');
const windows = require('./windows.js');

unhandled();
debug();
contextMenu();
if (is.windows) {
windows().then();
}

// Note: Must match `build.appId` in package.json
app.setAppUserModelId('com.company.AppName');
app.setAppUserModelId('me.lucasfreitas.WhatsAppCaller');
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('tel', process.execPath, [path.resolve(process.argv[1])])
app.setAsDefaultProtocolClient('callto', process.execPath, [path.resolve(process.argv[1])])
}
} else {
app.setAsDefaultProtocolClient('tel');
app.setAsDefaultProtocolClient('callto');
}

// Uncomment this before publishing your first version.
// It's commented out as it throws an error if there are no published versions.
Expand All @@ -34,12 +46,12 @@ const createMainWindow = async () => {
const win = new BrowserWindow({
title: app.name,
show: false,
width: 600,
height: 400
width: 1,
height: 1
});

win.on('ready-to-show', () => {
win.show();
// win.show();
});

win.on('closed', () => {
Expand All @@ -48,8 +60,6 @@ const createMainWindow = async () => {
mainWindow = undefined;
});

await win.loadFile(path.join(__dirname, 'index.html'));

return win;
};

Expand All @@ -69,9 +79,7 @@ app.on('second-instance', () => {
});

app.on('window-all-closed', () => {
if (!is.macos) {
app.quit();
}
app.quit();
});

app.on('activate', async () => {
Expand All @@ -80,11 +88,33 @@ app.on('activate', async () => {
}
});

const parseNumber = (number) => {
const cleanRegex = new RegExp(/^(\+)|\D/, 'g');
let cleanNumber = String(number).trim();
cleanNumber.replace(/^(tel|callto):\/\//, '');
cleanNumber = cleanNumber.replace(cleanRegex, '$1');
if (cleanNumber.startsWith("0")) {
cleanNumber = "49" + cleanNumber.substr(1);
}
return cleanNumber;
};

app.on('open-url', async (event, url) => {
await handleWhatsAppLink(mainWindow, parseNumber(url));
app.quit();
});

const handleWhatsAppLink = async (win, string) => {
await shell.openExternal(`whatsapp://send?phone=${string}`);
}

const noop =
(request, callback) => {};

(async () => {
await app.whenReady();
protocol.registerStringProtocol('callto', noop);
protocol.registerStringProtocol('tel', noop);
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();

const favoriteAnimal = config.get('favoriteAnimal');
mainWindow.webContents.executeJavaScript(`document.querySelector('header p').textContent = 'Your favorite animal is ${favoriteAnimal}'`);
})();
Loading

0 comments on commit 6ac9563

Please sign in to comment.