Skip to content

Commit

Permalink
Merge pull request #48 from FLock-io/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
rodrigopavezi authored Sep 13, 2023
2 parents b4f68f2 + f5306af commit c23c4e6
Show file tree
Hide file tree
Showing 13 changed files with 565 additions and 82 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This new FLock client interface boasts a state-of-the-art graphical user interfa
- Flexible with any model that implements the required interface
- Handle training and evaluation of the models

You may download the desktop client of the lastest version [here](https://github.com/FLock-io/client-interface/releases/tag/v0.0.5).
You may download the desktop client of the lastest version [here](https://github.com/FLock-io/client-interface/releases/tag/v0.0.6).

For more detailed technical explanation of the FLock client, see [here](https://docs.flock.io/core-technologies/flock-client/client-deepdown).

Expand Down
Binary file added build/bin/main.exe
Binary file not shown.
58 changes: 55 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "FLock Client",
"version": "0.0.5",
"version": "0.0.6",
"keywords": [
"electron",
"boilerplate",
Expand Down Expand Up @@ -113,6 +113,7 @@
"grommet": "^2.32.2",
"grommet-icons": "^4.11.0",
"ipfs-http-client": "^60.0.1",
"node-jose": "^2.2.0",
"polished": "^4.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -197,6 +198,12 @@
"appId": "io.Flock",
"asar": true,
"asarUnpack": "**\\*.{node,dll}",
"protocols": {
"name": "electron-deep-linking",
"schemes": [
"flock"
]
},
"files": [
"dist",
"node_modules",
Expand Down
4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flock-client",
"version": "0.0.5",
"version": "0.0.6",
"description": "FLock Client",
"license": "MIT",
"author": {
Expand Down
53 changes: 48 additions & 5 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* When running `npm run build` or `npm run build:main`, this file is compiled to
* `./src/main.js` using webpack. This gives us some performance wins.
*/
import path from 'path';
import path, { resolve } from 'path';
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
Expand Down Expand Up @@ -44,6 +44,7 @@ class AppUpdater {

let mainWindow: BrowserWindow | null = null;
let main: ChildProcessWithoutNullStreams;
let deeplinkingUrl;

ipcMain.handle('ipc', async (event, arg) => {
if (arg[0] === 'uploadToIPFS') {
Expand Down Expand Up @@ -136,6 +137,16 @@ if (process.env.NODE_ENV === 'production') {
const isDebug =
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';

const isDev = process.env.NODE_ENV === 'development';

if (isDev && process.platform === 'win32') {
app.setAsDefaultProtocolClient('flock', process.execPath, [
resolve(process.argv[1]),
]);
} else {
app.setAsDefaultProtocolClient('flock');
}

if (isDebug) {
require('electron-debug')();
}
Expand All @@ -153,6 +164,32 @@ const installExtensions = async () => {
.catch(console.log);
};

// Force Single Instance Application
const gotTheLock = app.requestSingleInstanceLock();
if (gotTheLock) {
app.on('second-instance', (e, argv) => {
// Someone tried to run a second instance, we should focus our window.

// Protocol handler for win32
// argv: An array of the second instance’s (command line / deep linked) arguments
if (process.platform === 'win32') {
// Keep only command line / deep linked arguments
deeplinkingUrl = argv.slice(1);
}
if (process.platform !== 'darwin') {
// Find the arg that is our custom protocol url and store it
deeplinkingUrl = argv.find((arg) => arg.startsWith('flock://test'));
}

if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
} else {
app.quit();
}

const createWindow = async () => {
if (isDebug) {
await installExtensions();
Expand All @@ -175,7 +212,7 @@ const createWindow = async () => {
preload: app.isPackaged
? path.join(__dirname, 'preload.js')
: path.join(__dirname, '../../.erb/dll/preload.js'),
devTools: false,
// devTools: false,
},
});

Expand All @@ -189,9 +226,9 @@ const createWindow = async () => {
icon: getAssetPath(getIcon()),
transparent: true,
frame: false,
webPreferences: {
devTools: false,
},
// webPreferences: {
// devTools: false,
// },
});

const splashScreenSrc = app.isPackaged
Expand Down Expand Up @@ -249,6 +286,12 @@ app.on('window-all-closed', () => {
}
});

// Protocol handler for osx
app.on('open-url', (event, url) => {
event.preventDefault();
deeplinkingUrl = url;
});

app
.whenReady()
.then(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { polygonMumbai } from 'wagmi/chains';
import { publicProvider } from 'wagmi/providers/public';
import { alchemyProvider } from 'wagmi/providers/alchemy';
import { Web3AuthConnector } from '@web3auth/web3auth-wagmi-connector';
import { Web3Auth } from '@web3auth/modal';
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider';
import { OpenloginAdapter } from '@web3auth/openlogin-adapter';
import Dashboard from './pages/Dashboard';
Expand All @@ -15,8 +14,8 @@ import { WalletContextProvider } from './context/walletContext';
import Faucet from './pages/Faucet';
import { CONFIG } from './config';
import { RunnerContextProvider } from './context/runnerContext';
import { useEffect, useState } from 'react';
import { web3AuthInstance } from './Web3AuthInstance'
import { web3AuthInstance } from './Web3AuthInstance';
import CustomConnector from './CustomConnector';

export default function App() {
const flockTheme = {
Expand Down Expand Up @@ -98,6 +97,7 @@ export default function App() {
web3AuthInstance,
},
}),
new CustomConnector({ chains: [polygonMumbai], options: {} }),
],
publicClient,
webSocketPublicClient,
Expand Down
102 changes: 102 additions & 0 deletions src/renderer/CustomConnector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Chain, Connector, ConnectorData, WalletClient } from '@wagmi/core';
import { privateKeyToAccount } from 'viem/accounts';
import { PrivateKeyAccount, createWalletClient, http } from 'viem';
import { CONFIG } from './config';

export default class CustomConnector extends Connector<any, any> {
readonly id = 'privateKey';

readonly name = 'Private Key Wallet';

readonly ready = true;

#provider?: any;

#account?: PrivateKeyAccount;

constructor({ chains, options }: { chains?: Chain[]; options: any }) {
super({ chains, options });
}

async getProvider() {
if (!this.#provider) {
// Initialize the provider with the Ethereum JSON-RPC endpoint
this.#provider = http(CONFIG.WEB3_AUTH_RPC);
}
return this.#provider;
}

async getAccount() {
const privateKey = await this.getPrivateKey();

// Set up the provider with the private key
const account = privateKeyToAccount(privateKey);
this.#account = account;
// return checksum address
return account.address;
}

async getPrivateKey() {
return localStorage.getItem('privateKey');
}

async setPrivateKey(privateKey: string) {
localStorage.setItem('privateKey', privateKey);
}

async connect({ chainId }: { chainId?: number } = {}): Promise<
Required<ConnectorData>
> {
try {
this.emit('message', {
type: 'connecting',
});

await this.getProvider();
await this.getAccount();

return {
account: this.#account?.address as `0x${string}`,
chain: {
id: Number(chainId),
unsupported: false,
},
};
} catch (error) {
console.error(error);
throw error;
}
}

async getWalletClient({
chainId,
}: { chainId?: number } = {}): Promise<WalletClient> {
if (!this.#provider) {
await this.getProvider();
}
await this.getAccount();

const chain = this.chains.find((x) => x.id === chainId);

return createWalletClient({
account: this.#account,
chain,
transport: this.#provider,
});
}

async isAuthorized() {
try {
await this.getAccount();
return !!this.#account;
} catch {
return false;
}
}

async disconnect() {
// Clear the private key and provider
this.setPrivateKey(undefined);
this.#provider = undefined;
}
}
Loading

0 comments on commit c23c4e6

Please sign in to comment.