Skip to content

Commit

Permalink
app: Add Go To Home Screen menu under view section
Browse files Browse the repository at this point in the history
We need a way to directly go to home screen from an app menu.
  • Loading branch information
ashu8912 committed Jul 1, 2024
1 parent 0d9ccad commit b370083
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions app/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ dotenv.config({ path: path.join(process.resourcesPath, '.env') });
const pathInfoDebug = false;
let pathInfo;

const isDev = process.env.ELECTRON_DEV || false;
let frontendPath = '';

if (isDev) {
frontendPath = path.resolve('..', 'frontend', 'build', 'index.html');
} else {
frontendPath = path.join(process.resourcesPath, 'frontend', 'index.html');
}
const backendToken = randomBytes(32).toString('hex');

const startUrl = (
process.env.ELECTRON_START_URL ||
url.format({
pathname: frontendPath,
protocol: 'file:',
slashes: true,
query: {
backendToken: backendToken,
},
})
)
// Windows paths use backslashes and for consistency we want to use forward slashes.
// For example: when application triggers refresh it requests a URL with forward slashes and
// we use startUrl to determine if it's an internal or external URL. So it's easier to
// convert everything to forward slashes.
.replace(/\\/g, '/');

/**
* On MacOS apps do not get the same environment variables as the terminal.
*
Expand Down Expand Up @@ -86,9 +113,7 @@ const args = yargs
const isHeadlessMode = args.headless;
let disableGPU = args['disable-gpu'];
const defaultPort = 4466;
const backendToken = randomBytes(32).toString('hex');

const isDev = process.env.ELECTRON_DEV || false;
const useExternalServer = process.env.EXTERNAL_SERVER || false;
const shouldCheckForUpdates = process.env.HEADLAMP_CHECK_FOR_UPDATES !== 'false';
const manifestDir = isDev ? path.resolve('./') : process.resourcesPath;
Expand Down Expand Up @@ -319,6 +344,14 @@ function getDefaultAppMenu(): AppMenu[] {
role: 'forcereload',
id: 'original-force-reload',
},
{
label: i18n.t('Go To Home Screen'),
role: 'homescreen',
id: 'original-home-screen',
click: () => {
mainWindow?.loadURL(startUrl);
},
},
{
label: i18n.t('Toggle Developer Tools'),
role: 'toggledevtools',
Expand Down Expand Up @@ -549,30 +582,6 @@ function startElecron() {
console.log('Check for updates: ', shouldCheckForUpdates);

async function createWindow() {
let frontendPath = '';
if (isDev) {
frontendPath = path.resolve('..', 'frontend', 'build', 'index.html');
} else {
frontendPath = path.join(process.resourcesPath, 'frontend', 'index.html');
}

const startUrl = (
process.env.ELECTRON_START_URL ||
url.format({
pathname: frontendPath,
protocol: 'file:',
slashes: true,
query: {
backendToken: backendToken,
},
})
)
// Windows paths use backslashes and for consistency we want to use forward slashes.
// For example: when application triggers refresh it requests a URL with forward slashes and
// we use startUrl to determine if it's an internal or external URL. So it's easier to
// convert everything to forward slashes.
.replace(/\\/g, '/');

// WSL has a problem with full size window placement, so make it smaller.
const withMargin = isWSL();
const { width, height } = windowSize(screen.getPrimaryDisplay().workAreaSize, withMargin);
Expand Down

0 comments on commit b370083

Please sign in to comment.