Skip to content

Commit

Permalink
Hide sort if no files are available. (UnchartedBull#750)
Browse files Browse the repository at this point in the history
* reformat + hide sort

* fix electron build
  • Loading branch information
UnchartedBull authored and kantlivelong committed May 5, 2021
1 parent 67a037a commit b122922
Show file tree
Hide file tree
Showing 39 changed files with 3,761 additions and 3,257 deletions.
232 changes: 113 additions & 119 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,154 +1,148 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const {
app,
BrowserWindow,
ipcMain,
session
} = require('electron');
const url = require('url');
const path = require('path');
const fs = require('fs');
const Store = require('electron-store');
const { app, BrowserWindow, ipcMain } = require("electron");
const url = require("url");
const path = require("path");
const fs = require("fs");
const Store = require("electron-store");

const store = new Store();
const exec = require('child_process').exec;
const exec = require("child_process").exec;

const args = process.argv.slice(1);
const dev = args.some(val => val === '--serve');
const big = args.some(val => val === '--big');
const dev = args.some((val) => val === "--serve");
const big = args.some((val) => val === "--big");

app.commandLine.appendSwitch('touch-events', 'enabled');
app.commandLine.appendSwitch("touch-events", "enabled");
app.allowRendererProcessReuse = true;

let window;

function createWindow() {
config = store.get('config');
store.onDidChange('config', newValue => {
config = newValue;
});

const {
screen,
session
} = require('electron');

if (!dev) {
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': ['script-src \'self\'']
}
})
})
}

const mainScreen = screen.getPrimaryDisplay();

window = new BrowserWindow({
width: dev ? (big ? 1400 : 1080) : mainScreen.size.width,
height: dev ? (big ? 502 : 342) : mainScreen.size.height,
frame: dev ? true : false,
backgroundColor: '#353b48',
webPreferences: {
nodeIntegration: true,
config = store.get("config");
store.onDidChange("config", (newValue) => {
config = newValue;
});

const { screen, session } = require("electron");

if (!dev) {
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
// TODO: re-enable
// "Content-Security-Policy": ["script-src 'self'"],
},
icon: path.join(__dirname, 'src/assets/icon.png'),
});
});

if (dev) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`),
});
window.loadURL('http://localhost:4200');
window.webContents.openDevTools();
} else {
window.loadURL(
url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true,
}),
);
window.setFullScreen(true);
}

// setTimeout(sendVersionInfo, 30 * 1000);
activateAppInfoListener();
activateScreenSleepListener();
activateReloadListener();

window.on('closed', () => {
window = null;
}

const mainScreen = screen.getPrimaryDisplay();

window = new BrowserWindow({
width: dev ? (big ? 1400 : 1080) : mainScreen.size.width,
height: dev ? (big ? 502 : 342) : mainScreen.size.height,
frame: dev ? true : false,
backgroundColor: "#353b48",
webPreferences: {
nodeIntegration: true,
},
icon: path.join(__dirname, "src", "assets", "icon", "icon.png"),
});

if (dev) {
require("electron-reload")(__dirname, {
electron: require(`${__dirname}/node_modules/electron`),
});
window.loadURL("http://localhost:4200");
window.webContents.openDevTools();
} else {
window.loadURL(
url.format({
pathname: path.join(__dirname, "dist/index.html"),
protocol: "file:",
slashes: true,
})
);
window.setFullScreen(true);
}

// setTimeout(sendVersionInfo, 30 * 1000);
activateAppInfoListener();
activateScreenSleepListener();
activateReloadListener();

window.on("closed", () => {
window = null;
});
}

function activateScreenSleepListener() {
ipcMain.on('screenSleep', () => {
exec('xset dpms force standby');
});

ipcMain.on('screenWakeup', () => {
exec('xset s off');
exec('xset -dpms');
exec('xset s noblank');
});
ipcMain.on("screenSleep", () => {
exec("xset dpms force standby");
});

ipcMain.on("screenWakeup", () => {
exec("xset s off");
exec("xset -dpms");
exec("xset s noblank");
});
}

function activateReloadListener() {
ipcMain.on('reload', () => {
window.loadURL(
url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true,
}),
);
});
ipcMain.on("reload", () => {
window.loadURL(
url.format({
pathname: path.join(__dirname, "dist/index.html"),
protocol: "file:",
slashes: true,
})
);
});
}

function activateAppInfoListener() {
ipcMain.on('appInfo', () => {
sendCustomStyles();
sendVersionInfo();
})
ipcMain.on("appInfo", () => {
sendCustomStyles();
sendVersionInfo();
});
}

function sendCustomStyles() {
fs.readFile(path.join(app.getPath('userData'), 'custom-styles.css'), 'utf-8', (err, data) => {
if (err) {
if (err.code === 'ENOENT') {
fs.writeFile(path.join(app.getPath('userData'), 'custom-styles.css'), '', (err) => {
if (err) {
window.webContents.send('customStylesError', err)
} else {
window.webContents.send('customStyles', '')
}
})
} else {
window.webContents.send('customStylesError', err)
}
} else {
window.webContents.send('customStyles', data)
}
})
fs.readFile(path.join(app.getPath("userData"), "custom-styles.css"), "utf-8", (err, data) => {
if (err) {
if (err.code === "ENOENT") {
fs.writeFile(path.join(app.getPath("userData"), "custom-styles.css"), "", (err) => {
if (err) {
window.webContents.send("customStylesError", err);
} else {
window.webContents.send("customStyles", "");
}
});
} else {
window.webContents.send("customStylesError", err);
}
} else {
window.webContents.send("customStyles", data);
}
});
}

function sendVersionInfo() {
window.webContents.send('versionInformation', {
version: app.getVersion(),
});
window.webContents.send("versionInformation", {
version: app.getVersion(),
});
}

app.on('ready', createWindow);
app.on("ready", createWindow);

app.on('window-all-closed', () => {
app.quit();
app.on("window-all-closed", () => {
app.quit();
});

app.on('activate', () => {
if (window === null) {
createWindow();
}
app.on("activate", () => {
if (window === null) {
createWindow();
}
});
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-simple-import-sort": "^5.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"ts-node": "~8.10.2",
"typescript": "^3.7.5",
"wait-on": "^5.0.1"
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ text_input() {


releaseURL=$(curl -s "https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest" | grep "browser_download_url.*armv7l.deb" | cut -d '"' -f 4)
dependencies="libgtk-3-0 libnotify4 libnss3 libxss1 libxtst6 xdg-utils libatspi2.0-0 libuuid1 libappindicator3-1 libsecret-1-0 gir1.2-gnomekeyring-1.0 xserver-xorg ratpoison x11-xserver-utils xinit libgtk-3-0 bc"
dependencies="libgtk-3-0 libnotify4 libnss3 libxss1 libxtst6 xdg-utils libatspi2.0-0 libuuid1 libappindicator3-1 libsecret-1-0 gir1.2-gnomekeyring-1.0 xserver-xorg ratpoison x11-xserver-utils xinit libgtk-3-0 bc desktop-file-utils"
IFS='/' read -ra version <<< "$releaseURL"

echo "Installing OctoDash "${version[7]}
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<app-notification></app-notification>
<div class="container">
<router-outlet></router-outlet>
<router-outlet></router-outlet>
</div>
8 changes: 4 additions & 4 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.container {
width: 100%;
height: 100%;
display: block;
position: relative;
width: 100%;
height: 100%;
display: block;
position: relative;
}
1 change: 0 additions & 1 deletion src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class AppService {

private enableCustomCSSListener(): void {
this.ipc.on("customStyles", (_, customCSS: string): void => {
console.log(customCSS);
const css = document.createElement("style");
css.type = "text/css";
css.appendChild(document.createTextNode(customCSS));
Expand Down
19 changes: 10 additions & 9 deletions src/app/bottom-bar/bottom-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<table class="bottom-bar">
<tr>
<td class="bottom-bar__printer-name"> {{ printer.name }} </td>
<td class="bottom-bar__enclosure-temperature" *ngIf="enclosureTemperature">
<img src="assets/thermometer.svg" class="bottom-bar__enclosure-temperature-icon" />
{{ enclosureTemperature.temperature }}{{ enclosureTemperature.unit }}
</td>
<td class="bottom-bar__current-status" [ngClass]="{'bottom-bar__error': printer.status.includes('error')}">
{{ printer.status }} </td>
</tr>
<tr>
<td class="bottom-bar__printer-name">{{ printer.name }}</td>
<td class="bottom-bar__enclosure-temperature" *ngIf="enclosureTemperature">
<img src="assets/thermometer.svg" class="bottom-bar__enclosure-temperature-icon" />
{{ enclosureTemperature.temperature }}{{ enclosureTemperature.unit }}
</td>
<td class="bottom-bar__current-status" [ngClass]="{ 'bottom-bar__error': printer.status.includes('error') }">
{{ printer.status }}
</td>
</tr>
</table>
Loading

0 comments on commit b122922

Please sign in to comment.