Skip to content

Commit

Permalink
Merge pull request #202 from jessedp/cron
Browse files Browse the repository at this point in the history
Make autoRebuild more useful fixes #48
  • Loading branch information
jessedp authored Apr 25, 2023
2 parents 99e36b5 + 9ce4119 commit 649fc3c
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 148 deletions.
2 changes: 1 addition & 1 deletion @types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare var navigator: Navigator;

declare var discoveredDevices: Array<any>;

declare var CONNECTED: boolean;
declare var isConnected: boolean;

declare var EXPORTING: boolean;

Expand Down
14 changes: 14 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 @@ -281,6 +281,7 @@
"check-disk-space": "^3.3.1",
"compare-versions": "^5.0.3",
"connected-react-router": "^6.9.2",
"croner": "^6.0.3",
"date-fns": "^2.8.1",
"debug": "^4.3.4",
"deep-object-diff": "^1.1.9",
Expand Down
6 changes: 3 additions & 3 deletions src/main/pre_Tablo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ ipcMain.on('tablo-setCurrentDevice', async (event: any, device: any) => {
}
});

ipcMain.on('tablo-CONNECTED', async (event: any) => {
ipcMain.on('tablo-isConnected', async (event: any) => {
try {
event.returnValue = global.CONNECTED;
event.returnValue = global.isConnected;
} catch (e) {
console.error('tablo-CONNECTED', e);
console.error('tablo-isConnected', e);
event.returnValue = false;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contextBridge.exposeInMainWorld('Tablo', {
checkConnection: () => ipcRenderer.sendSync('tablo-checkConnection'),
comskipAvailable: () => ipcRenderer.sendSync('tablo-comskipAvailable'),
hasDevice: () => ipcRenderer.sendSync('tablo-has-device'),
CONNECTED: () => ipcRenderer.sendSync('tablo-CONNECTED'),
isConnected: () => ipcRenderer.sendSync('tablo-isConnected'),
device: () => ipcRenderer.sendSync('tablo-device'),
discoveredDevices: () => ipcRenderer.sendSync('tablo-discoveredDevices'),
getRecordingsCount: () => ipcRenderer.sendSync('tablo-getRecordingsCount'),
Expand Down
6 changes: 3 additions & 3 deletions src/main/utils/Tablo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export async function checkConnection(): Promise<boolean> {

return new Promise((resolve) => {
client.on('close', () => {
global.CONNECTED = status;
global.isConnected = status;
resolve(status);
});
});
Expand All @@ -165,7 +165,7 @@ export async function checkConnection(): Promise<boolean> {
export const comskipAvailable = (): boolean => {
const currentDevice: any = store.get('CurrentDevice');

if (!global.CONNECTED) return false;
if (!global.isConnected) return false;
if (!currentDevice.server_version) return false;
const testVersion = currentDevice.server_version.match(/[\d.]*/)[0];
const supportedVersion = '2.2.26';
Expand All @@ -191,7 +191,7 @@ export const comskipAvailable = (): boolean => {
export async function setupApi(): Promise<void> {
debug('Calling setupApi');
globalThis.Api = new Tablo();
global.CONNECTED = false;
global.isConnected = false;
debug('Calling discover');
await discover();
debug('Discover finished');
Expand Down
39 changes: 7 additions & 32 deletions src/renderer/components/Build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { bindActionCreators } from 'redux';
import { writeToFile } from '../utils/utils';
import getConfig from '../utils/config';

import { dbCreatedKey, recDbCreated } from '../utils/db';
import { dbCreatedKey } from '../utils/db';

import * as BuildActions from '../store/build';
import { DbSliceState } from '../store/build';
Expand Down Expand Up @@ -49,35 +49,9 @@ class Build extends Component<BuildProps, State> {
this.build = this.build.bind(this);
}

async componentDidMount() {
let created = recDbCreated();

// TODO: some const export?
if (!created) {
let i = 0;

const autoBuild = async () => {
created = recDbCreated();

if (!window.Tablo.device() && !created) {
if (i > 0) return;
i += 1;
setTimeout(autoBuild, 5000);
}

if (window.Tablo.device() && !created) this.build();
};

autoBuild();
}
}

componentDidUpdate(prevProps: BuildProps) {
const { progress } = this.props;
if (
prevProps.progress.loading !== progress.loading &&
progress.loading === STATE_START
) {
if (progress.loading === STATE_START) {
this.build();
}
}
Expand All @@ -88,17 +62,18 @@ class Build extends Component<BuildProps, State> {
if (!window.Tablo.device()) return;

if (this.building) {
console.log('trying to double build');
console.warn('trying to double build');
return;
}
this.building = true;

if (!window.Tablo.CONNECTED()) {
console.log('Not connected, not bulding...');
if (!window.Tablo.isConnected()) {
console.warn('Not connected, not bulding...');
return;
}

if (global.EXPORTING) {
console.log('Exporting, not bulding...');
console.warn('Exporting, not building...');
return;
}

Expand Down
1 change: 0 additions & 1 deletion src/renderer/components/DbStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default class DbStats extends Component<Props, State> {
}

async refresh() {
// const { RecDb } = global;
const recTotal = window.db.countAsync('RecDb', {});

/** Watched * */
Expand Down
Loading

0 comments on commit 649fc3c

Please sign in to comment.