Skip to content

Commit

Permalink
Merge pull request #141 from ajthinking/refactor-24-1
Browse files Browse the repository at this point in the history
Show open file in app header
  • Loading branch information
ajthinking committed Feb 25, 2024
2 parents aed6081 + 9a3152b commit 346028a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 0 additions & 3 deletions packages/desktop/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
connect-src 'self' ws://localhost:3100;
style-src 'self' 'unsafe-inline';
">

<title>DataStory</title>

</head>
<body>
<div id="root"></div>
Expand Down
24 changes: 22 additions & 2 deletions packages/desktop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { IpcResult } from './types';
// ************************************************************************************************
// Electron app, window etc
// ************************************************************************************************
let mainWindow: BrowserWindow;


// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
Expand Down Expand Up @@ -69,6 +71,16 @@ ipcMain.handle('open-diagram', async(): Promise<IpcResult> => {
if (!file.canceled && file.filePaths.length > 0) {
result.data = await fsAsync.readFile(file.filePaths[0], 'utf8');
result.isSuccess = true;

if (mainWindow) {
const workspace = file.filePaths[0]; // Or extract a more specific workspace name from the filePath
mainWindow.setTitle(`Data Story - ${workspace}`);

// Persisting the workspace setting
const settings = readSettings(); // Assuming this function synchronously returns the settings object
settings.workspace = workspace; // Update the workspace setting
writeSettings(settings); // Assuming this function takes the settings object and saves it
}
}
return result;
} catch(err) {
Expand All @@ -79,7 +91,7 @@ ipcMain.handle('open-diagram', async(): Promise<IpcResult> => {

const createWindow = (): void => {
// Create the browser window.
const mainWindow = new BrowserWindow({
mainWindow = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
Expand Down Expand Up @@ -118,13 +130,21 @@ app.on('ready', () => {
const settings = readSettings();
writeSettings(settings);
if (settings.workspace) loadEnvs(settings.workspace);

mainWindow.setTitle(`Data Story - ${settings.workspace || 'Untitled'}`);
});

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
createWindow()

const settings = readSettings();
writeSettings(settings);
if (settings.workspace) loadEnvs(settings.workspace);

mainWindow.setTitle(`Data Story - ${settings.workspace || 'Untitled'}`);
}
});

Expand Down

0 comments on commit 346028a

Please sign in to comment.