Skip to content

Commit

Permalink
feat: Electron build for Mac and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Dec 13, 2021
1 parent 3d6db88 commit cb52d03
Show file tree
Hide file tree
Showing 4 changed files with 1,376 additions and 102 deletions.
120 changes: 60 additions & 60 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
# Build folder and files #
##########################
builds/

# Development folders and files #
#################################
.tmp/
dist/
coverage/
node_modules/
public/
*.compiled.*
settings.json
pages.json
*.shot
*.ccg

# Folder config file #
######################
Desktop.ini

# Folder notes #
################
_ignore/

# Log files & folders #
#######################
logs/
*.log
npm-debug.log*
.npm

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Photoshop & Illustrator files #
#################################
*.ai
*.eps
*.psd

# Windows & Mac file caches #
#############################
.DS_Store
Thumbs.db
ehthumbs.db

# Windows shortcuts #
#####################
*.lnk
# Build folder and files #
##########################
builds/

# Development folders and files #
#################################
.tmp/
dist/
coverage/
node_modules/
release/
*.compiled.*
settings.json
pages.json
*.shot
*.ccg

# Folder config file #
######################
Desktop.ini

# Folder notes #
################
_ignore/

# Log files & folders #
#######################
logs/
*.log
npm-debug.log*
.npm

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Photoshop & Illustrator files #
#################################
*.ai
*.eps
*.psd

# Windows & Mac file caches #
#############################
.DS_Store
Thumbs.db
ehthumbs.db

# Windows shortcuts #
#####################
*.lnk
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"npm": ">=5.0.0",
"yarn": ">=1.0.0"
},
"main": "dist/server/index.js",
"main": "public/electron.js",
"scripts": {
"electron-release": "electron-builder -mw",
"start": "node dist/server/index.js",
"start:dev": "node --inspect dist/server/index.js",
"start:break": "node --inspect-brk dist/server/index.js",
Expand Down Expand Up @@ -84,6 +85,7 @@
"redux": "^4.0.5",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.0",
"tslib": "^2.3.1",
"utf-8-validate": "^5.0.4",
"vmix-js-utils": "^4.0.7",
"web-midi-api": "^2.0.8",
Expand All @@ -103,6 +105,8 @@
"@types/react-test-renderer": "^17.0.1",
"@types/socket.io-client": "^1.4.36",
"css-loader": "^5.2.4",
"electron": "^16.0.4",
"electron-builder": "^22.14.5",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.1",
"jest": "^26.6.3",
Expand Down Expand Up @@ -135,5 +139,17 @@
"path-parse": "^1.0.7",
"ansi-regex": "^5.0.1",
"axios": "^0.21.2"
},
"build": {
"appId": "com.sisyfos-audio-controller.app",
"asar": true,
"files": [
"dist/**/*",
"public/**/*",
"!release/**/*"
],
"directories": {
"output": "release"
}
}
}
52 changes: 34 additions & 18 deletions server/utils/SettingsStorage.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Node Modules:
const fs = require('fs')
const path = require('path')
const homeDir = require('os').homedir()
const platform = require('os').platform()

import { store } from '../reducers/store'
import { checkVersion } from './migrations'

// Redux:
import { storeSetCompleteChState } from '../reducers/channelActions'
import { storeSetCompleteFaderState } from '../reducers/faderActions'
import { logger } from './logger'
import { InumberOfChannels } from '../reducers/channelsReducer'
import { IChannels, InumberOfChannels } from '../reducers/channelsReducer'
import { IFaders } from '../reducers/fadersReducer'
import { IChannels } from '../reducers/channelsReducer'

import { ICustomPages, ISettings } from '../reducers/settingsReducer'

Expand All @@ -19,11 +21,20 @@ export interface IShotStorage {
faderState: IFaders
}

// Linux place in "app"/storage to be backward compatible with Docker containers.
// Windows and Mac place the storagefolder in home -> sisyfos-storage
let storageFolder: string
if (platform === 'linux') {
storageFolder = 'storage'
} else {
storageFolder = path.resolve(homeDir, 'sisyfos-storage')
}

export const loadSettings = (storeRedux: any): ISettings => {
let newSettings = storeRedux.settings[0]
try {
newSettings = JSON.parse(
fs.readFileSync(path.resolve('storage', 'settings.json'))
fs.readFileSync(path.resolve(storageFolder, 'settings.json'))
)
checkVersion(newSettings)
return newSettings
Expand All @@ -40,11 +51,11 @@ export const saveSettings = (settings: any) => {
const settingsCopy = { ...settings }
delete settingsCopy.customPages
let json = JSON.stringify(settingsCopy)
if (!fs.existsSync('storage')) {
fs.mkdirSync('storage')
if (!fs.existsSync(storageFolder)) {
fs.mkdirSync(storageFolder)
}
fs.writeFile(
path.resolve('storage', 'settings.json'),
path.resolve(storageFolder, 'settings.json'),
json,
'utf8',
(error: any) => {
Expand Down Expand Up @@ -98,7 +109,7 @@ export const saveSnapshotState = (stateSnapshot: any, fileName: string) => {

export const getSnapShotList = (): string[] => {
const files = fs
.readdirSync(path.resolve('storage'))
.readdirSync(path.resolve(storageFolder))
.filter((file: string) => {
if (file.includes('.shot') && file !== 'default.shot') {
return true
Expand All @@ -112,7 +123,7 @@ export const getMixerPresetList = (fileExtension: string): string[] => {
return []
}
const files = fs
.readdirSync(path.resolve('storage'))
.readdirSync(path.resolve(storageFolder))
.filter((file: string) => {
if (
file.toUpperCase().includes('.' + fileExtension.toUpperCase())
Expand All @@ -125,7 +136,7 @@ export const getMixerPresetList = (fileExtension: string): string[] => {

export const getCcgSettingsList = () => {
const files = fs
.readdirSync(path.resolve('storage'))
.readdirSync(path.resolve(storageFolder))
.filter((file: string) => {
if (file.includes('.ccg') && file !== 'default-casparcg.ccg') {
return true
Expand All @@ -137,13 +148,13 @@ export const getCcgSettingsList = () => {
export const setCcgDefault = (fileName: string) => {
let data: any
try {
data = fs.readFileSync(path.join('storage', fileName))
data = fs.readFileSync(path.join(storageFolder, fileName))
} catch (error) {
logger.error('Couldn´t read ' + fileName + ' file')
return
}

const defaultFile = path.join('storage', 'default-casparcg.ccg')
const defaultFile = path.join(storageFolder, 'default-casparcg.ccg')
fs.writeFile(defaultFile, data, 'utf8', (error: any) => {
if (error) {
logger.data(error).error('Error setting default CasparCG setting')
Expand All @@ -156,7 +167,7 @@ export const setCcgDefault = (fileName: string) => {
export const getCustomPages = (): ICustomPages[] => {
try {
return JSON.parse(
fs.readFileSync(path.resolve('storage', 'pages.json'))
fs.readFileSync(path.resolve(storageFolder, 'pages.json'))
)
} catch (error) {
logger.error('Couldn´t read pages.json file')
Expand All @@ -169,11 +180,16 @@ export const saveCustomPages = (
fileName: string = 'pages.json'
) => {
let json = JSON.stringify(stateCustomPages)
fs.writeFile(path.join('storage', fileName), json, 'utf8', (error: any) => {
if (error) {
logger.data(error).error('Error saving pages file')
} else {
logger.info('Pages ' + fileName + ' Saved to storage folder')
fs.writeFile(
path.join(storageFolder, fileName),
json,
'utf8',
(error: any) => {
if (error) {
logger.data(error).error('Error saving pages file')
} else {
logger.info('Pages ' + fileName + ' Saved to storage folder')
}
}
})
)
}
Loading

0 comments on commit cb52d03

Please sign in to comment.