Skip to content

Commit

Permalink
feat: set new CasparCG config from Storage Menu is working.
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 28, 2020
1 parent 7dde12f commit 7eab0b9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public/
*.compiled.*
settings.json
*.shot

*.ccg

# Folder config file #
######################
Expand Down
38 changes: 19 additions & 19 deletions client/components/RoutingStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
SOCKET_GET_SNAPSHOT_LIST,
SOCKET_LOAD_SNAPSHOT,
SOCKET_SAVE_SNAPSHOT,
SOCKET_GET_CCG_LIST
SOCKET_GET_CCG_LIST,
SOCKET_SAVE_CCG_FILE
} from '../../server/constants/SOCKET_IO_DISPATCHERS';

interface IStorageProps {
Expand Down Expand Up @@ -59,8 +60,8 @@ class Storage extends React.PureComponent<IStorageProps & Store> {
loadCcgFile(event: any) {
if (window.confirm('Are you sure you will load a CasparCG setup?'))
{
console.log('Loading files')
window.socketIoClient.emit(SOCKET_LOAD_SNAPSHOT, event.target.textContent)
console.log('Setting default CasparCG file')
window.socketIoClient.emit(SOCKET_SAVE_CCG_FILE, event.target.textContent)
}
this.handleClose()
}
Expand All @@ -69,12 +70,11 @@ class Storage extends React.PureComponent<IStorageProps & Store> {
ListSnapshotFiles() {
window.socketIoClient.emit(SOCKET_GET_SNAPSHOT_LIST)
const listItems = window.snapshotFileList.map((file: string, index: number) => {
return (
<li key={index} onClick={this.loadFile} className="item">
{file}
</li>)
}
);
return (
<li key={index} onClick={this.loadFile} className="item">
{file}
</li>)
});
return (
<ul className="storage-list">
{listItems}
Expand All @@ -85,17 +85,17 @@ class Storage extends React.PureComponent<IStorageProps & Store> {
ListCcgFiles() {
window.socketIoClient.emit(SOCKET_GET_CCG_LIST)
const listItems = window.ccgFileList.map((file: string, index: number) => {
return (
<li key={index} onClick={this.loadCcgFile} className="item">
{file}
</li>
)
})
return (
<li key={index} onClick={this.loadFile} className="item">
{file}
</li>)
}
);
return (
<ul className="storage-list">
{listItems}
</ul>
);
<ul className="storage-list">
{listItems}
</ul>
)
}

render() {
Expand Down
13 changes: 11 additions & 2 deletions server/MainThreadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
loadSettings,
saveSettings,
getSnapShotList,
getCcgSettingsList
getCcgSettingsList,
setCcgDefault
} from './utils/SettingsStorage'
import {
SOCKET_TOGGLE_PGM,
Expand Down Expand Up @@ -40,7 +41,8 @@ import {
SOCKET_SET_STORE_FADER,
SOCKET_SET_STORE_CHANNEL,
SOCKET_SET_LO_MID,
SOCKET_SET_INPUT_OPTION
SOCKET_SET_INPUT_OPTION,
SOCKET_SAVE_CCG_FILE
} from './constants/SOCKET_IO_DISPATCHERS'
import {
TOGGLE_PGM,
Expand Down Expand Up @@ -168,6 +170,13 @@ export class MainThreadHandlers {
)
})
)
.on(SOCKET_SAVE_CCG_FILE, (
(payload: any) => {
logger.info('Set default CCG File :' + String(payload), {})
setCcgDefault(payload)
this.updateFullClientStore()
})
)
.on(SOCKET_SAVE_SETTINGS, (
(payload: any) => {
logger.info('Save settings :' + String(payload), {})
Expand Down
1 change: 1 addition & 0 deletions server/constants/SOCKET_IO_DISPATCHERS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const SOCKET_GET_CCG_LIST = 'getCcgList'
export const SOCKET_RETURN_CCG_LIST = 'returnCcgList'
export const SOCKET_LOAD_SNAPSHOT = 'loadSnapshot'
export const SOCKET_SAVE_SNAPSHOT = 'saveSnapshot'
export const SOCKET_SAVE_CCG_FILE = 'saveCcgFile'

// Store updates:
export const SOCKET_SET_FULL_STORE = 'setFullStore'
Expand Down
24 changes: 23 additions & 1 deletion server/utils/SettingsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,31 @@ export const getSnapShotList = () => {

export const getCcgSettingsList = () => {
const files = fs.readdirSync(path.resolve('storage')).filter((file: string) => {
if (file.includes('.ccg')) {
if (file.includes('.ccg') && file !== 'default-casparcg.ccg') {
return true
}
})
return files
}

export const setCcgDefault = (fileName: string) => {
let data: any
try {
data = fs.readFileSync(path.join('storage', fileName))
}
catch (error) {
logger.error('Couldn´t read ' + fileName + ' file', {})
return
}

const defaultFile = path.join('storage', 'default-casparcg.ccg')
fs.writeFile(defaultFile, data, 'utf8', (error: any)=>{
if (error) {
logger.error("Error setting default CasparCG setting" + String(error), {})
} else {
logger.info('CasparCG' + fileName + ' Saved as default CasparCG', {})
}
});


}

0 comments on commit 7eab0b9

Please sign in to comment.