Skip to content

Commit 69e1072

Browse files
committed
Refactored into a restart() and APPIMAGE fix attempt
1 parent 702aa53 commit 69e1072

File tree

2 files changed

+57
-35
lines changed

2 files changed

+57
-35
lines changed

.github/workflows/build-dna.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ jobs:
1313
shell: bash # important because this runs shell scripts
1414
run: |
1515
npm run ci:hc-install
16-
# build dna
17-
- name: Build DNA
18-
run: |
19-
npm run build:happ
2016
# Hash Zome
2117
- name: Hash Zome Install
2218
run: |
2319
npm run hash-zome-install
20+
# build dna
21+
- name: Build DNA
22+
run: |
23+
npm run build:happ
2424
- name: Hash Zome Install
2525
run: |
2626
npm run hash-zome

electron/src/index.ts

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
MenuItemConstructorOptions, nativeImage,
99
Notification,
1010
screen,
11+
RelaunchOptions,
1112
shell, Tray
1213
} from 'electron'
1314
import * as path from 'path'
@@ -28,7 +29,7 @@ import {
2829
BINARY_PATHS,
2930
} from './holochain'
3031

31-
import {electronLogger, log} from './logger'
32+
import { electronLogger, log } from './logger'
3233
import { loadUserSettings } from './userSettings'
3334

3435
import {
@@ -43,6 +44,8 @@ import {
4344
import {initApp, addUidToDisk} from "./init";
4445
import * as prompt from 'electron-prompt';
4546

47+
import { execFile } from 'child_process'
48+
4649
export const delay = (ms:number) => new Promise(r => setTimeout(r, ms))
4750

4851
//--------------------------------------------------------------------------------------------------
@@ -72,6 +75,7 @@ let g_runner_version = 'holochain runner version (unknown)'
7275
let g_lair_version = 'lair version (unknown)'
7376
let g_dnaHash = '(unknown)'
7477

78+
7579
//--------------------------------------------------------------------------------------------------
7680
// -- Functions
7781
//--------------------------------------------------------------------------------------------------
@@ -119,7 +123,7 @@ const createMainWindow = async (appPort: string): Promise<BrowserWindow> => {
119123
mainUrl += "?PORT=" + appPort + "&UID=" + g_uid
120124
log('info', "createMainWindow ; mainUrl = " + mainUrl)
121125
try {
122-
await mainWindow.loadURL("file://" + mainUrl)
126+
await mainWindow.loadURL("file://" + mainUrl)
123127
} catch(err) {
124128
log('error', 'loadURL() failed:');
125129
log('error',{err});
@@ -151,11 +155,11 @@ const createMainWindow = async (appPort: string): Promise<BrowserWindow> => {
151155
g_userSettings.set('windowPosition', { x: Math.floor(positions[0]), y: Math.floor(positions[1]) });
152156
if (g_canQuit) {
153157
log('info', 'WINDOW EVENT "close" -> canQuit')
154-
//await try_shutdown();
155-
mainWindow = null;
158+
//await try_shutdown();
159+
mainWindow = null;
156160
} else {
157-
event.preventDefault();
158-
mainWindow.hide();
161+
event.preventDefault();
162+
mainWindow.hide();
159163
}
160164
})
161165

@@ -238,9 +242,9 @@ const createSplashWindow = (): BrowserWindow => {
238242

239243

240244
/**
241-
* This method will be called when Electron has finished initialization and is ready to create browser windows.
242-
* Some APIs can only be used after this event occurs.
243-
*/
245+
* This method will be called when Electron has finished initialization and is ready to create browser windows.
246+
* Some APIs can only be used after this event occurs.
247+
*/
244248
app.on('ready', async () => {
245249
log('debug', "ELECTRON READY - " + __dirname)
246250
const splashWindow = createSplashWindow()
@@ -441,7 +445,7 @@ ipc.on('dnaHash', (event, dnaHash) => {
441445
* PROMPTS
442446
*************************************************************************************************/
443447

444-
/**
448+
/**
445449
* @returns false if user cancelled
446450
*/
447451
async function promptUid(canExitOnCancel: boolean, parentBrowserWindow: BrowserWindow) {
@@ -576,6 +580,39 @@ async function promptHolochainError(browserWindow: BrowserWindow, msg: string) {
576580
// },
577581
// ];
578582

583+
async function restart() {
584+
log('debug', "*** Restarting...");
585+
g_mainWindow = null;
586+
//g_statusEmitter = null;
587+
//await try_shutdown();
588+
log('debug', "*** Restarting: RELAUNCH");
589+
590+
if (app.isPackaged && process.env.APPIMAGE) {
591+
log('debug', "*** ... with APPIMAGE: " + process.env.APPIMAGE);
592+
//log('debug', "*** ... with execPath: " + process.execPath);
593+
594+
// // Pipe errors if console.log() is called + plus possible other issues when relaunching again
595+
// const options: RelaunchOptions = {
596+
// args: process.argv.slice(1).concat(['--relaunch']),
597+
// execPath: process.execPath
598+
// };
599+
// execFile(process.env.APPIMAGE, options.args);
600+
// app.quit();
601+
// return;
602+
603+
// FUSE can still fail
604+
let options: RelaunchOptions = {
605+
execPath: process.env.APPIMAGE,
606+
args:['--appimage-extract-and-run']
607+
};
608+
//console.log({options})
609+
app.relaunch(options)
610+
} else {
611+
app.relaunch()
612+
}
613+
app.exit(0)
614+
}
615+
579616

580617
/**
581618
* In this file you can include the rest of your app's specific main process code.
@@ -588,13 +625,7 @@ const networkMenuTemplate: Array<MenuItemConstructorOptions> = [
588625
click: async function (menuItem, browserWindow, _event) {
589626
let changed = await promptUid(false, g_mainWindow);
590627
if (changed) {
591-
console.log("*** Joining...");
592-
g_mainWindow = null;
593-
//g_statusEmitter = null;
594-
//await try_shutdown();
595-
app.relaunch()
596-
//app.exit(0)
597-
app.quit()
628+
await restart()
598629
}
599630
},
600631
},
@@ -604,14 +635,7 @@ const networkMenuTemplate: Array<MenuItemConstructorOptions> = [
604635
click: async function (menuItem, _browserWindow, _event) {
605636
let changed = await promptUidSelect(false);
606637
if (changed) {
607-
console.log("*** Switching...");
608-
g_mainWindow = null;
609-
//g_statusEmitter = null;
610-
//await try_shutdown();
611-
console.log("*** Switching: RELAUNCH");
612-
app.relaunch()
613-
//app.exit(0)
614-
app.quit()
638+
await restart()
615639
}
616640
},
617641
},
@@ -687,9 +711,7 @@ const debugMenuTemplate: Array<MenuItemConstructorOptions> = [
687711
{
688712
label: 'Restart Holochain',
689713
click: async function (menuItem, _browserWindow, _event) {
690-
//await startConductorAndLoadPage(false);
691-
app.relaunch()
692-
app.exit(0)
714+
await restart()
693715
}
694716
},
695717
{
@@ -701,6 +723,7 @@ const debugMenuTemplate: Array<MenuItemConstructorOptions> = [
701723
},
702724
];
703725

726+
704727
/**
705728
*
706729
*/
@@ -769,16 +792,15 @@ export const mainMenuTemplate: Array<MenuItemConstructorOptions> = [
769792
*/
770793
const trayMenuTemplate: Array<MenuItemConstructorOptions> = [
771794
{ label: 'Tray / Untray', click: function (menuItem, _browserWindow, _event) {
772-
g_mainWindow.isVisible()? g_mainWindow.hide() : g_mainWindow.show();
795+
g_mainWindow.isVisible()? g_mainWindow.hide() : g_mainWindow.show();
773796
}
774797
},
775798
{
776799
label: 'Switch network',
777800
click: async function (menuItem, _browserWindow, _event) {
778801
let changed = await promptUidSelect(false);
779802
if(changed) {
780-
app.relaunch()
781-
app.exit(0)
803+
await restart()
782804
}
783805
}
784806
},

0 commit comments

Comments
 (0)