Browse Source
* add mac min/max * restore exitfromtray * fix macos quiting * upgrade to electron 22 * Remove unused components / react-dnd --------- Co-authored-by: jeffvli <jeffvictorli@gmail.com>master
Kendall Garner
2 years ago
committed by
GitHub
62 changed files with 4472 additions and 4637 deletions
@ -0,0 +1,86 @@ |
|||
export default class Store { |
|||
constructor(options={}) { |
|||
this.name = options.name || "config.json"; |
|||
this.settings = options.defaults || {}; |
|||
} |
|||
|
|||
get store() { |
|||
return this.set; |
|||
} |
|||
|
|||
set store(value) { |
|||
this.settings = value; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param {string} key |
|||
*/ |
|||
_getParentObject(key) { |
|||
const path = key.split("."); |
|||
const final = path.at(-1); |
|||
let object = this.settings; |
|||
|
|||
for (const part of path.slice(0, -1)) { |
|||
object = object[part]; |
|||
|
|||
if (object === undefined) { |
|||
return [undefined, final]; |
|||
} |
|||
} |
|||
|
|||
return [object, final]; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param {string} key |
|||
*/ |
|||
has(key) { |
|||
if (key.indexOf(".") !== -1) { |
|||
let [parent, final] = this._getParentObject(key); |
|||
return parent !== undefined && key in parent; |
|||
} else { |
|||
return key in this.settings; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param {string} key |
|||
*/ |
|||
get(key) { |
|||
if (key.indexOf(".") !== -1) { |
|||
let [parent, final] = this._getParentObject(key); |
|||
|
|||
return parent !== undefined ? parent[final] : undefined; |
|||
} else { |
|||
return this.settings[key]; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param {string} key |
|||
* @param {any} value |
|||
*/ |
|||
set(key, value) { |
|||
if (key.indexOf("." !== -1)) { |
|||
const path = key.split("."); |
|||
|
|||
let object = this.settings; |
|||
|
|||
for (const part of path.slice(0, -1)) { |
|||
if (!(part in object)) { |
|||
object[part] = {}; |
|||
} |
|||
|
|||
object = object[part]; |
|||
} |
|||
|
|||
object[path.at(-1)] = value; |
|||
} else { |
|||
this.settings[key] = value; |
|||
} |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -1,50 +0,0 @@ |
|||
import React from 'react'; |
|||
import { useDrag, useDrop } from 'react-dnd'; |
|||
import { Table } from 'rsuite'; |
|||
|
|||
const ItemTypes = { |
|||
COLUMN: 'column', |
|||
ROW: 'row', |
|||
}; |
|||
|
|||
const DraggableCell = ({ children, onDrag, id, rowData, ...rest }: any) => { |
|||
const ref = React.useRef(null); |
|||
|
|||
const [{ canDrop, isOver }, drop] = useDrop({ |
|||
accept: ItemTypes.ROW, |
|||
collect: (monitor) => ({ |
|||
isOver: monitor.isOver(), |
|||
canDrop: monitor.canDrop(), |
|||
}), |
|||
drop(item: any) { |
|||
onDrag(item.id, rowData.id); |
|||
}, |
|||
}); |
|||
|
|||
const [{ isDragging }, drag] = useDrag({ |
|||
type: ItemTypes.ROW, |
|||
item: { id: rowData.id, type: ItemTypes.ROW }, |
|||
collect: (monitor) => ({ |
|||
isDragging: monitor.isDragging(), |
|||
}), |
|||
}); |
|||
|
|||
const isActive = canDrop && isOver; |
|||
|
|||
drag(drop(ref)); |
|||
|
|||
const styles = { |
|||
opacity: isDragging ? 0.5 : 1, |
|||
background: isActive ? '#ddd' : undefined, |
|||
}; |
|||
|
|||
return ( |
|||
<Table.Cell {...rest} style={{ padding: 0 }}> |
|||
<div ref={ref} style={styles}> |
|||
{children} |
|||
</div> |
|||
</Table.Cell> |
|||
); |
|||
}; |
|||
|
|||
export default DraggableCell; |
@ -1,50 +0,0 @@ |
|||
import React from 'react'; |
|||
import { useDrag, useDrop } from 'react-dnd'; |
|||
import { Table } from 'rsuite'; |
|||
|
|||
const ItemTypes = { |
|||
COLUMN: 'column', |
|||
ROW: 'row', |
|||
}; |
|||
|
|||
const DraggableHeaderCell = ({ children, onDrag, id, ...rest }: any) => { |
|||
const ref = React.useRef(null); |
|||
|
|||
const [{ canDrop, isOver }, drop] = useDrop({ |
|||
accept: ItemTypes.COLUMN, |
|||
collect: (monitor) => ({ |
|||
isOver: monitor.isOver(), |
|||
canDrop: monitor.canDrop(), |
|||
}), |
|||
drop(item: any) { |
|||
onDrag(item.id, id); |
|||
}, |
|||
}); |
|||
|
|||
const [{ isDragging }, drag] = useDrag({ |
|||
type: ItemTypes.COLUMN, |
|||
item: { id, type: ItemTypes.COLUMN }, |
|||
collect: (monitor) => ({ |
|||
isDragging: monitor.isDragging(), |
|||
}), |
|||
}); |
|||
const isActive = canDrop && isOver; |
|||
|
|||
drag(drop(ref)); |
|||
|
|||
return ( |
|||
<Table.HeaderCell {...rest} style={{ padding: 0 }}> |
|||
<div |
|||
ref={ref} |
|||
style={{ |
|||
opacity: isDragging ? 0 : 1, |
|||
backgroundColor: isActive ? '#3B4552' : undefined, |
|||
}} |
|||
> |
|||
{children} |
|||
</div> |
|||
</Table.HeaderCell> |
|||
); |
|||
}; |
|||
|
|||
export default DraggableHeaderCell; |
@ -1,50 +0,0 @@ |
|||
const { remote } = require('electron'); |
|||
|
|||
const win = remote.getCurrentWindow(); /* Note this is different to the |
|||
html global `window` variable */ |
|||
|
|||
window.onbeforeunload = () => { |
|||
/* If window is reloaded, remove win event listeners |
|||
(DOM element listeners get auto garbage collected but not |
|||
Electron win listeners as the win is not dereferenced unless closed) */ |
|||
win.removeAllListeners(); |
|||
}; |
|||
|
|||
function handleWindowControls() { |
|||
// Make minimise/maximise/restore/close buttons work when they are clicked
|
|||
document.getElementById('min-button')?.addEventListener('click', () => { |
|||
win.minimize(); |
|||
}); |
|||
|
|||
document.getElementById('max-button')?.addEventListener('click', () => { |
|||
win.maximize(); |
|||
}); |
|||
|
|||
document.getElementById('restore-button')?.addEventListener('click', () => { |
|||
win.unmaximize(); |
|||
}); |
|||
|
|||
document.getElementById('close-button')?.addEventListener('click', () => { |
|||
win.close(); |
|||
}); |
|||
|
|||
function toggleMaxRestoreButtons() { |
|||
if (win.isMaximized()) { |
|||
document.body.classList.add('maximized'); |
|||
} else { |
|||
document.body.classList.remove('maximized'); |
|||
} |
|||
} |
|||
|
|||
// Toggle maximise/restore buttons when maximisation/unmaximisation occurs
|
|||
toggleMaxRestoreButtons(); |
|||
win.on('maximize', toggleMaxRestoreButtons); |
|||
win.on('unmaximize', toggleMaxRestoreButtons); |
|||
} |
|||
|
|||
// When document has loaded, initialise
|
|||
document.onreadystatechange = () => { |
|||
if (document.readyState === 'complete') { |
|||
handleWindowControls(); |
|||
} |
|||
}; |
File diff suppressed because it is too large
Loading…
Reference in new issue