use app.isPackaged instead of checking for node env development (#5465)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -768,7 +768,7 @@ const createTray = () => {
|
|||||||
// If tray already exists, destroy it first
|
// If tray already exists, destroy it first
|
||||||
destroyTray();
|
destroyTray();
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const isDev = !app.isPackaged;
|
||||||
let iconPath: string;
|
let iconPath: string;
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
|
|||||||
@@ -248,7 +248,6 @@ export function setupAutoUpdater(tray?: Tray) {
|
|||||||
log.info('Setting up auto-updater...');
|
log.info('Setting up auto-updater...');
|
||||||
log.info(`Current app version: ${app.getVersion()}`);
|
log.info(`Current app version: ${app.getVersion()}`);
|
||||||
log.info(`Platform: ${process.platform}, Arch: ${process.arch}`);
|
log.info(`Platform: ${process.platform}, Arch: ${process.arch}`);
|
||||||
log.info(`NODE_ENV: ${process.env.NODE_ENV}`);
|
|
||||||
log.info(`ENABLE_DEV_UPDATES: ${process.env.ENABLE_DEV_UPDATES}`);
|
log.info(`ENABLE_DEV_UPDATES: ${process.env.ENABLE_DEV_UPDATES}`);
|
||||||
log.info(`App is packaged: ${app.isPackaged}`);
|
log.info(`App is packaged: ${app.isPackaged}`);
|
||||||
log.info(`App path: ${app.getAppPath()}`);
|
log.info(`App path: ${app.getAppPath()}`);
|
||||||
@@ -470,7 +469,7 @@ function sendStatusToWindow(event: string, data?: unknown) {
|
|||||||
function updateTrayIcon(hasUpdate: boolean) {
|
function updateTrayIcon(hasUpdate: boolean) {
|
||||||
if (!trayRef) return;
|
if (!trayRef) return;
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const isDev = !app.isPackaged;
|
||||||
let iconPath: string;
|
let iconPath: string;
|
||||||
|
|
||||||
if (hasUpdate) {
|
if (hasUpdate) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// Import the proper type from ConfigContext
|
|
||||||
import { getApiUrl } from '../config';
|
import { getApiUrl } from '../config';
|
||||||
import { safeJsonParse } from './conversionUtils';
|
import { safeJsonParse } from './conversionUtils';
|
||||||
|
|
||||||
@@ -206,49 +205,3 @@ export async function fetchAndCachePricing(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh pricing data from backend
|
|
||||||
*/
|
|
||||||
export async function refreshPricing(): Promise<boolean> {
|
|
||||||
try {
|
|
||||||
// Clear session cache to force re-fetch
|
|
||||||
sessionPricingCache.clear();
|
|
||||||
|
|
||||||
// The actual refresh happens on the backend when we call with configured_only: false
|
|
||||||
const apiUrl = getApiUrl('/config/pricing');
|
|
||||||
const secretKey = await window.electron.getSecretKey();
|
|
||||||
|
|
||||||
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
||||||
if (secretKey) {
|
|
||||||
headers['X-Secret-Key'] = secretKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
|
||||||
method: 'POST',
|
|
||||||
headers,
|
|
||||||
body: JSON.stringify({ configured_only: false }),
|
|
||||||
});
|
|
||||||
|
|
||||||
return response.ok;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expose functions for testing in development mode
|
|
||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
getCostForModel?: typeof getCostForModel;
|
|
||||||
fetchAndCachePricing?: typeof fetchAndCachePricing;
|
|
||||||
refreshPricing?: typeof refreshPricing;
|
|
||||||
sessionPricingCache?: typeof sessionPricingCache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development' || typeof window !== 'undefined') {
|
|
||||||
window.getCostForModel = getCostForModel;
|
|
||||||
window.fetchAndCachePricing = fetchAndCachePricing;
|
|
||||||
window.refreshPricing = refreshPricing;
|
|
||||||
window.sessionPricingCache = sessionPricingCache;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,21 +2,11 @@ import log from 'electron-log';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { app } from 'electron';
|
import { app } from 'electron';
|
||||||
|
|
||||||
// Configure electron-log
|
|
||||||
// In development: ~/Library/Logs/goose/main.log
|
|
||||||
// In production: ~/Library/Application Support/goose/logs/main.log
|
|
||||||
log.transports.file.resolvePathFn = () => {
|
log.transports.file.resolvePathFn = () => {
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
return path.join(app.getPath('userData'), 'logs', 'main.log');
|
||||||
if (isDev) {
|
|
||||||
return path.join(app.getPath('home'), 'Library/Logs/goose/main.log');
|
|
||||||
}
|
|
||||||
return path.join(app.getPath('userData'), 'logs/main.log');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Configure log level based on environment
|
log.transports.file.level = app.isPackaged ? 'info' : 'debug';
|
||||||
log.transports.file.level = process.env.NODE_ENV === 'development' ? 'debug' : 'info';
|
log.transports.console.level = app.isPackaged ? false : 'debug';
|
||||||
|
|
||||||
// Also log to console in development
|
|
||||||
log.transports.console.level = process.env.NODE_ENV === 'development' ? 'debug' : false;
|
|
||||||
|
|
||||||
export default log;
|
export default log;
|
||||||
|
|||||||
@@ -71,9 +71,7 @@ const addPaths = (
|
|||||||
executableName: string,
|
executableName: string,
|
||||||
app: Electron.App
|
app: Electron.App
|
||||||
): void => {
|
): void => {
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
if (!app.isPackaged) {
|
||||||
const isPackaged = app.isPackaged;
|
|
||||||
if (isDev && !isPackaged) {
|
|
||||||
possiblePaths.push(
|
possiblePaths.push(
|
||||||
path.join(process.cwd(), 'src', 'bin', executableName),
|
path.join(process.cwd(), 'src', 'bin', executableName),
|
||||||
path.join(process.cwd(), 'bin', executableName),
|
path.join(process.cwd(), 'bin', executableName),
|
||||||
|
|||||||
Reference in New Issue
Block a user