Skip to content

Commit

Permalink
added placeholder session view
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolba committed Nov 15, 2022
1 parent 749aaf3 commit 528584c
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 15 deletions.
6 changes: 6 additions & 0 deletions packages/main/src/handlers/runtime/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const openToolsMenu = async (message: RuntimeMessage) => {
}
},
},
{
label: 'View Session',
click: async () => {
await workspace.createSessionView();
},
},
];

const menu = Menu.buildFromTemplate(template);
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/types/ViewConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export interface ViewConfig {
directoryData?: DirectoryApp;

version?: FDC3_VERSIONS;

title?: string;

isSystem?: boolean;
}
35 changes: 21 additions & 14 deletions packages/main/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class View {
this.parent = parent;
if (config) {
this.directoryData = config.directoryData;
this.title = config.title;
}

if (fdc3Version) {
Expand All @@ -92,11 +93,16 @@ export class View {

console.log('View - fdc3Version', this.fdc3Version);

const preload = url
? this.fdc3Version === '1.2'
? FDC3_1_2_PRELOAD
: FDC3_2_0_PRELOAD
: HOME_PRELOAD;
const isSystem = config?.isSystem || url === undefined ? true : false;
let preload;

if (isSystem) {
this.type = 'system';
preload = HOME_PRELOAD;
} else {
preload =
this.fdc3Version === '1.2' ? FDC3_1_2_PRELOAD : FDC3_2_0_PRELOAD;
}

this.content = new BrowserView({
webPreferences: {
Expand All @@ -122,6 +128,7 @@ export class View {
}
if (url === (VIEW_DEFAULT as string)) {
this.type = 'system';
this.title = 'Home';
}

if (url) {
Expand Down Expand Up @@ -154,6 +161,7 @@ export class View {
});
}
}

/**
* size the view to the parent
*/
Expand Down Expand Up @@ -198,6 +206,8 @@ export class View {

initiated = false;

title?: string;

fdc3Version: '2.0' | '1.2' = '2.0';

private type: 'system' | 'app' = 'app';
Expand Down Expand Up @@ -249,15 +259,12 @@ export class View {
};

getTitle(): string {
//is it a system view?
console.log('View getTitle', this.isSystemView());
if (this.isSystemView()) {
return 'Home';
} else {
return this.directoryData && this.directoryData.title
? this.directoryData.title
: this.content.webContents.getTitle();
}
console.log('****getTItle', this.title);
return this.title
? this.title
: this.directoryData && this.directoryData.title
? this.directoryData.title
: this.content.webContents.getTitle();
}

close() {
Expand Down
21 changes: 21 additions & 0 deletions packages/main/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,27 @@ export class Workspace {
});
}

/**
* create a developer view of the Session State
*/
async createSessionView(): Promise<void> {
const VIEW_PATH =
import.meta.env.DEV &&
import.meta.env.VITE_DEV_SERVER_SESSION_URL !== undefined
? import.meta.env.VITE_DEV_SERVER_SESSION_URL
: new URL(
'../renderer/dist/sessionView.html',
'file://' + __dirname,
).toString();

this.createView(VIEW_PATH, {
workspace: this,
isSystem: true,
title: 'Session View',
});
return;
}

createChannelWindow(): Promise<void> {
return new Promise((resolve, reject) => {
this.channelWindow = new BrowserWindow({
Expand Down
8 changes: 8 additions & 0 deletions packages/preload/src/system/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ const getSessionState = () => {
const results = args.data;
resolve(results);
});

if (id) {
// Get the session state
ipcRenderer.send(RUNTIME_TOPICS.GET_SESSION_STATE, {
source: id,
data: {},
});
} else {
eventQ.push(() => {
ipcRenderer.send(RUNTIME_TOPICS.GET_SESSION_STATE, {
source: id,
data: {},
});
});
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/homeView.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
content="script-src 'self' blob:"
/>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>FDC3 Desktop Agent</title>
<title>Home</title>

</head>
<body>
Expand Down
18 changes: 18 additions & 0 deletions packages/renderer/sessionView.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="script-src 'self' blob:"
/>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Sail Desktop Agent</title>

</head>
<body>
<div id="sessionView"></div>
<script src="./sessionView/src/index.tsx" type="module"></script>
</body>

</html>
42 changes: 42 additions & 0 deletions packages/renderer/sessionView/src/SessionView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { Paper } from '@mui/material';
import { SessionState } from '../../../main/src/types/SessionState';

export class SessionView extends React.Component<
{},
{ session: SessionState }
> {
constructor(props) {
super(props);
this.state = { session: props.session };
}

componentDidMount() {
const onFDC3Ready = async () => {
//fetch apps from the directory, using system API (only available to system apps)

const session = await globalThis.sail.getSessionState();

this.setState({ session: session });
};
if (window.fdc3) {
onFDC3Ready();
} else {
document.addEventListener('fdc3Ready', onFDC3Ready);
}
}

render() {
return (
<Paper
sx={{
padding: '1rem',
margin: '1rem',
backgroundColor: '#ccc',
}}
>
{JSON.stringify(this.state.session)}
</Paper>
);
}
}
Empty file.
12 changes: 12 additions & 0 deletions packages/renderer/sessionView/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SessionView } from './SessionView';
import React from 'react';
import ReactDOM from 'react-dom';

import './index.css';

ReactDOM.render(
<React.StrictMode>
<SessionView />
</React.StrictMode>,
document.getElementById('sessionView'),
);
1 change: 1 addition & 0 deletions packages/renderer/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const config = {
input: {
index: 'index.html',
homeView: 'homeView.html',
sessionView: 'sessionView.html',
channelPicker: 'channelPicker.html',
intentResolver: 'intentResolver.html',
searchResults: 'searchResults.html',
Expand Down
1 change: 1 addition & 0 deletions scripts/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const setupMainPackageWatcher = ({ config: { server } }) => {
process.env.VITE_DEV_SERVER_URL = `${protocol}//${host}:${port}${path}`;
process.env.VITE_DEV_SERVER_FRAME_URL = `${protocol}//${host}:${port}${path}index.html`;
process.env.VITE_DEV_SERVER_DEFAULT_URL = `${protocol}//${host}:${port}${path}homeView.html`;
process.env.VITE_DEV_SERVER_SESSION_URL = `${protocol}//${host}:${port}${path}sessionView.html`;
process.env.VITE_DEV_SERVER_CHANNEL_URL = `${protocol}//${host}:${port}${path}channelPicker.html`;
process.env.VITE_DEV_SERVER_SEARCH_URL = `${protocol}//${host}:${port}${path}searchResults.html`;
process.env.VITE_DEV_SERVER_INTENTS_URL = `${protocol}//${host}:${port}${path}intentResolver.html`;
Expand Down

0 comments on commit 528584c

Please sign in to comment.