Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ out
*.log*
packages
./ui
./main
main
.idea
scripts/*.js
/main/index.js
/main/index.js.map
/main/preload/chromealive.js
/main/preload/desktop.js
/main/preload/menubar.js
Binary file modified .yarn/install-state.gz
Binary file not shown.
3 changes: 0 additions & 3 deletions electron-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ module.exports = {
},
hardenedRuntime: true,
gatekeeperAssess: false,
extendInfo: {
LSUIElement: 1,
},
entitlements: 'build-resources/entitlements.mac.plist',
entitlementsInherit: 'build-resources/entitlements.mac.plist',
notarize: false, // do this manually
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulixee/desktop",
"version": "2.0.0-alpha.30",
"version": "2.0.0-alpha.31",
"description": "This is a builder project that uses the dual package.json approach (./app contains the app package.json).",
"private": true,
"author": "Ulixee Foundation",
Expand Down Expand Up @@ -29,24 +29,24 @@
"unpack:asar": "npx @electron/asar extract dist/mac/Ulixee.app/Contents/Resources/app.asar dist/mac/app_unpacked"
},
"dependencies": {
"@argonprotocol/localchain": "0.0.14",
"@argonprotocol/localchain": "0.0.20",
"@electron-toolkit/preload": "^3.0.0",
"@ulixee/cloud": "2.0.0-alpha.30",
"@ulixee/commons": "2.0.0-alpha.30",
"@ulixee/datastore": "2.0.0-alpha.30",
"@ulixee/datastore-core": "2.0.0-alpha.30",
"@ulixee/datastore-plugins-hero": "2.0.0-alpha.30",
"@ulixee/default-browser-emulator": "2.0.0-alpha.30",
"@ulixee/desktop-core": "2.0.0-alpha.30",
"@ulixee/desktop-interfaces": "2.0.0-alpha.30",
"@ulixee/hero-core": "2.0.0-alpha.30",
"@ulixee/hero-interfaces": "2.0.0-alpha.30",
"@ulixee/js-path": "2.0.0-alpha.30",
"@ulixee/net": "2.0.0-alpha.30",
"@ulixee/platform-specification": "2.0.0-alpha.30",
"@ulixee/platform-utils": "2.0.0-alpha.30",
"@ulixee/unblocked-agent-mitm-socket": "^2.0.0-alpha.30",
"@ulixee/unblocked-specification": "2.0.0-alpha.30",
"@ulixee/cloud": "2.0.0-alpha.31",
"@ulixee/commons": "2.0.0-alpha.31",
"@ulixee/datastore": "2.0.0-alpha.31",
"@ulixee/datastore-core": "2.0.0-alpha.31",
"@ulixee/datastore-plugins-hero": "2.0.0-alpha.31",
"@ulixee/default-browser-emulator": "2.0.0-alpha.31",
"@ulixee/desktop-core": "2.0.0-alpha.31",
"@ulixee/desktop-interfaces": "2.0.0-alpha.31",
"@ulixee/hero-core": "2.0.0-alpha.31",
"@ulixee/hero-interfaces": "2.0.0-alpha.31",
"@ulixee/js-path": "2.0.0-alpha.31",
"@ulixee/net": "2.0.0-alpha.31",
"@ulixee/platform-specification": "2.0.0-alpha.31",
"@ulixee/platform-utils": "2.0.0-alpha.31",
"@ulixee/unblocked-agent-mitm-socket": "^2.0.0-alpha.31",
"@ulixee/unblocked-specification": "2.0.0-alpha.31",
"better-sqlite3": "^11.1.2",
"electron-log": "^5.1.7",
"electron-updater": "^6.3.4",
Expand Down Expand Up @@ -98,7 +98,7 @@
"tailwindcss": "^3.4.1",
"ts-node": "^10.9.2",
"tslib": "^2.7.0",
"typescript": "^5.6.2",
"typescript": "~5.6.2",
"vite": "^5.3.1",
"vite-plugin-checker": "^0.8.0",
"vite-plugin-multiple": "^0.2.0",
Expand Down
14 changes: 7 additions & 7 deletions src/main/lib/AccountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default class AccountManager extends TypedEventEmitter<{
balance += account.balance;
}

const formattedBalance = ArgonUtils.format(balance, 'milligons', 'argons');
const formattedBalance = ArgonUtils.format(balance, 'microgons', 'argons');

return {
credits: [],
Expand Down Expand Up @@ -275,15 +275,15 @@ export default class AccountManager extends TypedEventEmitter<{
}

public async createArgonsToSendFile(request: {
milligons: bigint;
microgons: bigint;
fromAddress?: string;
toAddress?: string;
}): Promise<IArgonFileMeta> {
const localchain =
(await this.getLocalchain(request.fromAddress)) ?? this.getDefaultLocalchain();

const file = await localchain.transactions.send(
request.milligons,
request.microgons,
request.toAddress ? [request.toAddress] : null,
);
const argonFile = JSON.parse(file);
Expand All @@ -292,17 +292,17 @@ export default class AccountManager extends TypedEventEmitter<{
return {
rawJson: file,
file: ArgonFileSchema.parse(argonFile),
name: `${ArgonUtils.format(request.milligons, 'milligons', 'argons')} ${recipient}.${ARGON_FILE_EXTENSION}`,
name: `${ArgonUtils.format(request.microgons, 'microgons', 'argons')} ${recipient}.${ARGON_FILE_EXTENSION}`,
};
}

public async createArgonsToRequestFile(request: {
milligons: bigint;
microgons: bigint;
sendToMyAddress?: string;
}): Promise<IArgonFileMeta> {
const localchain =
(await this.getLocalchain(request.sendToMyAddress)) ?? this.getDefaultLocalchain();
const file = await localchain.transactions.request(request.milligons);
const file = await localchain.transactions.request(request.microgons);
const argonFile = JSON.parse(file);

return {
Expand All @@ -324,7 +324,7 @@ export default class AccountManager extends TypedEventEmitter<{
const funding = argonFile.request.reduce((sum, x) => {
if (x.accountType === 'deposit') {
for (const note of x.notes) {
if (note.noteType.action === 'claim') sum += note.milligons;
if (note.noteType.action === 'claim') sum += note.microgons;
}
}
return sum;
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class ApiClient<
}

public async connect(): Promise<void> {
await this.connection.connect(false, 15e3);
await this.connection.connect({ timeoutMs: 15e3, isAutoConnect: false });
this.isConnected = true;
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/lib/ApiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ export default class ApiManager<
if (!this.paymentService) throw new Error("Payment service isn't initialized");
const localchainWallet = await this.accountManager.getWallet();
const credits = await this.paymentService.credits();
const creditBalance = credits.reduce((sum, x) => sum + x.remaining, 0);
const creditMilligons = ArgonUtils.microgonsToMilligons(creditBalance);
const creditBalance = credits.reduce((sum, x) => sum + x.remaining, 0n);

const localchainBalance = localchainWallet.accounts.reduce(
(sum, x) => sum + x.balance + x.mainchainBalance,
Expand All @@ -179,8 +178,8 @@ export default class ApiManager<
const brokerBalance = localchainWallet.brokerAccounts.reduce((sum, x) => sum + x.balance, 0n);

const formattedBalance = ArgonUtils.format(
localchainBalance + creditMilligons + brokerBalance,
'milligons',
localchainBalance + creditBalance + brokerBalance,
'microgons',
'argons',
);

Expand Down Expand Up @@ -254,6 +253,10 @@ export default class ApiManager<
}
}

public async getCloudConnectionIdByAddress(address: string): Promise<string | undefined> {
return (await this.apiByCloudAddress.get(address)?.resolvable)?.id;
}

public async connectToCloud(cloud: ICloudSetup): Promise<void> {
const { adminIdentity, oldAddress, type } = cloud;
let { address, name } = cloud;
Expand Down
15 changes: 8 additions & 7 deletions src/main/lib/ChromeAliveWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { IChromeAliveSessionApis } from '@ulixee/desktop-interfaces/apis';
import IChromeAliveSessionEvents from '@ulixee/desktop-interfaces/events/IChromeAliveSessionEvents';
import ISessionAppModeEvent from '@ulixee/desktop-interfaces/events/ISessionAppModeEvent';
import HeroCore from '@ulixee/hero-core';
import { data } from 'autoprefixer';
import { app, BrowserWindow, MenuItem, screen, shell } from 'electron';
import { nanoid } from 'nanoid';
import * as Path from 'path';
import moment from 'moment';
import generateContextMenu from '../menus/generateContextMenu';
import ApiClient from './ApiClient';
import View from './View';
import loadUrl from './util/loadUrl';
import BrowserView = Electron.BrowserView;
import loadUrl, { getUrl } from './util/loadUrl';

// make electron packaging friendly
const extensionPath = Path.resolve(__dirname, '../ui').replace('app.asar', 'app.asar.unpacked');
Expand Down Expand Up @@ -58,7 +56,8 @@ export default class ChromeAliveWindow {
heroSessionId: string;
dbPath: string;
},
cloudAddress: string,
public cloudAddress: string,
public apiConnectionId: string,
) {
bindFunctions(this);
this.createApi(cloudAddress);
Expand Down Expand Up @@ -271,10 +270,9 @@ export default class ChromeAliveWindow {
return;
}

await devtoolsWc.executeJavaScript(
void devtoolsWc.executeJavaScript(
`(async () => {
while (typeof UI === 'undefined') {
console.log('waiting')
while (typeof UI?.panels?.elements?.parentWidgetInternal === 'undefined') {
await new Promise(resolve => setTimeout(resolve, 100));
}

Expand All @@ -293,6 +291,8 @@ export default class ChromeAliveWindow {
}
})()`,
);
// give the devtools a chance to load
await new Promise(setImmediate);
const target = await View.getTargetInfo(devtoolsWc);
await this.api?.send('Session.devtoolsTargetOpened', target);
});
Expand Down Expand Up @@ -335,6 +335,7 @@ export default class ChromeAliveWindow {
if (!this.session.dbPath.includes(HeroCore.dataDir)) {
address.searchParams.set('path', this.session.dbPath);
}
address.searchParams.set('id', this.apiConnectionId);
this.api = new ApiClient(address.href, this.onChromeAliveEvent);
// eslint-disable-next-line no-console
console.log('Window connected to %s', this.api.address);
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/DesktopWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class DesktopWindow extends TypedEventEmitter<{

constructor(private apiManager: ApiManager) {
super();
void this.open(false);
void this.open(true);
}

public focus(): void {
Expand Down
19 changes: 11 additions & 8 deletions src/main/lib/Menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ export class Menubar extends EventEmitter {
}

// hide the dock icon if it shows
if (process.platform === 'darwin') {
app.setActivationPolicy('accessory');
}
app.on('second-instance', this.onSecondInstance.bind(this));
app.on('open-file', this.onFileOpened.bind(this));
app.on('window-all-closed', () => {
console.log('window-all-closed');
if (process.platform !== 'darwin') { // On macOS, apps generally stay open until explicitly quit
app.quit();
}
});
app.setAppLogsPath();
(process.env as any).ELECTRON_DISABLE_SECURITY_WARNINGS = true;
void this.appReady();
Expand All @@ -55,6 +58,11 @@ export class Menubar extends EventEmitter {
return this.#tray;
}

public async appExit(): Promise<void> {
await this.beforeQuit();
app.exit();
}

private bindSignals(): void {
let didRun = false;
const exit = (): Promise<void> => {
Expand Down Expand Up @@ -141,11 +149,6 @@ export class Menubar extends EventEmitter {
}
}

private async appExit(): Promise<void> {
await this.beforeQuit();
app.exit();
}

private async appReady(): Promise<void> {
try {
await app.whenReady();
Expand Down
12 changes: 6 additions & 6 deletions src/main/lib/PrivateDesktopApiHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,35 @@ export default class PrivateDesktopApiHandler extends TypedEventEmitter<{
}

public async createArgonsToSendFile(request: {
milligons: bigint;
microgons: bigint;
fromAddress?: string;
toAddress?: string;
}): Promise<IArgonFileMeta> {
return this.apiManager.accountManager.createArgonsToSendFile(request);
}

public async transferArgonsFromMainchain(request: {
milligons: bigint;
microgons: bigint;
address: string;
}): Promise<void> {
await this.apiManager.accountManager.transferMainchainToLocal(
request.address,
request.milligons,
request.microgons,
);
}

public async transferArgonsToMainchain(request: {
milligons: bigint;
microgons: bigint;
address: string;
}): Promise<void> {
return this.apiManager.accountManager.transferLocalToMainchain(
request.address,
request.milligons,
request.microgons,
);
}

public async createArgonsToRequestFile(request: {
milligons: bigint;
microgons: bigint;
sendToMyAddress?: string;
}): Promise<IArgonFileMeta> {
return this.apiManager.accountManager.createArgonsToRequestFile(request);
Expand Down
16 changes: 10 additions & 6 deletions src/main/lib/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class WindowManager {

this.bindIpcEvents();
this.desktopWindow = new DesktopWindow(apiManager);
this.events.on(this.desktopWindow, 'close', this.checkOpenWindows.bind(this));
this.events.on(this.desktopWindow, 'close', this.close.bind(this));
this.events.on(this.desktopWindow, 'focus', this.setMenu.bind(this));
this.events.on(
apiManager.privateDesktopApiHandler,
Expand All @@ -43,13 +43,14 @@ export class WindowManager {
}

public async openDesktop(): Promise<void> {
await app.dock?.show();
this.setMenu();
await this.desktopWindow.open();
await this.desktopWindow.open(true);
}

public close(): void {
console.log('Closing Desktop');
this.events.close();
void this.menuBar.appExit();
}

public async loadChromeAliveWindow(data: {
Expand All @@ -61,8 +62,11 @@ export class WindowManager {
this.#chromeAliveWindowsBySessionId.get(data.heroSessionId)?.window.focus();
return;
}
await app.dock?.show();
const chromeAliveWindow = new ChromeAliveWindow(data, data.cloudAddress);
const connectionId = await this.apiManager.getCloudConnectionIdByAddress(data.cloudAddress);
if (!connectionId) {
throw new Error(`No connection found for cloud address ${data.cloudAddress}`);
}
const chromeAliveWindow = new ChromeAliveWindow(data, data.cloudAddress, connectionId);

const { heroSessionId } = data;
this.chromeAliveWindows.push(chromeAliveWindow);
Expand Down Expand Up @@ -167,7 +171,7 @@ export class WindowManager {

private checkOpenWindows(): void {
if (this.chromeAliveWindows.length === 0 && !this.desktopWindow.isOpen) {
app.dock?.hide();
app.quit();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/util/defaultEnvVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ if (app.isPackaged) {
process.env.DEBUG = [process.env.DEBUG ?? '', 'ulx:*'].filter(Boolean).join(',');
process.env.NODE_DISABLE_COLORS = 'true';
} else {
process.env.DEBUG = [process.env.DEBUG ?? '', 'ulx:*'].filter(Boolean).join(',');
process.env.DEBUG = [process.env.DEBUG ?? '', 'ulx'].filter(Boolean).join(',');
}
Loading
Loading