Fixed client UI cache
This commit is contained in:
parent
4a19f3a827
commit
edff7d4014
@ -123,5 +123,5 @@ function deploy_client() {
|
||||
#install_npm
|
||||
#compile_scripts
|
||||
#compile_native
|
||||
#package_client
|
||||
deploy_client
|
||||
package_client
|
||||
#deploy_client
|
||||
|
@ -183,25 +183,29 @@ async function loadCachedOrRemoteUiPack(channel: string, callbackStatus: (messag
|
||||
const bundledUi = await shippedClientUi();
|
||||
const clientVersion = await currentClientVersion();
|
||||
|
||||
console.error("Looking for downloaded up packs on channel %s", channel);
|
||||
let availableCachedVersions: CachedUIPack[] = localUiCache().cachedPacks.filter(e => {
|
||||
if(e.status.type !== "valid") {
|
||||
console.error("Not valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(e.packInfo.channel !== channel) {
|
||||
console.error("%s !== %s", e.packInfo.channel, channel);
|
||||
/* ui-pack is for another channel */
|
||||
return false;
|
||||
}
|
||||
|
||||
if(bundledUi) {
|
||||
/* remove all cached ui packs which are older than our bundled one */
|
||||
if(e.packInfo.timestamp <= bundledUi.downloadTimestamp) {
|
||||
if(e.packInfo.timestamp <= bundledUi.packInfo.timestamp) {
|
||||
console.error("%d <= %s", e.packInfo.timestamp, bundledUi.packInfo.timestamp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(e.packInfo.channel !== channel) {
|
||||
/* ui-pack is for another channel */
|
||||
return false;
|
||||
}
|
||||
|
||||
const requiredVersion = parseVersion(e.packInfo.requiredClientVersion);
|
||||
return clientVersion.isDevelopmentVersion() || clientVersion.newerThan(requiredVersion) || clientVersion.equals(requiredVersion);
|
||||
return clientVersion.isDevelopmentVersion() || clientVersion.newerThan(requiredVersion, true) || clientVersion.equals(requiredVersion);
|
||||
});
|
||||
|
||||
if(processArguments.has_flag(Arguments.UPDATER_UI_NO_CACHE)) {
|
||||
@ -209,6 +213,7 @@ async function loadCachedOrRemoteUiPack(channel: string, callbackStatus: (messag
|
||||
availableCachedVersions = [];
|
||||
}
|
||||
|
||||
console.error("Found %d local UI packs (%d not suitable).", availableCachedVersions.length, localUiCache().cachedPacks.length - availableCachedVersions.length);
|
||||
let remoteVersionDropped = false;
|
||||
|
||||
/* fetch the remote versions */
|
||||
|
@ -39,7 +39,7 @@ export class Version {
|
||||
if(other.patch != this.patch) return false;
|
||||
if(other.build != this.build) return false;
|
||||
|
||||
return other.timestamp == this.timestamp;
|
||||
return other.timestamp === 0 || this.timestamp === 0 || other.timestamp === this.timestamp;
|
||||
}
|
||||
|
||||
newerThan(other: Version, compareTimestamps?: boolean) : boolean {
|
||||
|
@ -3,55 +3,52 @@ import * as fs from "fs-extra";
|
||||
import * as path from "path";
|
||||
|
||||
/* We read/write to this file every time again because this file could be used by multiple processes */
|
||||
const data_file: string = path.join((electron.app || electron.remote.app).getPath('userData'), "window-bounds.json");
|
||||
const configFile: string = path.join((electron.app || electron.remote.app).getPath('userData'), "window-bounds.json");
|
||||
|
||||
import BrowserWindow = Electron.BrowserWindow;
|
||||
import Rectangle = Electron.Rectangle;
|
||||
|
||||
let changedData: {[key: string]:Rectangle} = {};
|
||||
let changedData: {[key: string]: Rectangle} = {};
|
||||
let changedDataSaveTimeout: number;
|
||||
|
||||
export async function save_changes() {
|
||||
export async function saveChanges() {
|
||||
clearTimeout(changedDataSaveTimeout);
|
||||
|
||||
try {
|
||||
const data = (await fs.pathExists(data_file) ? await fs.readJson(data_file) : {}) || {};
|
||||
const data = (await fs.pathExists(configFile) ? await fs.readJson(configFile) : {}) || {};
|
||||
Object.assign(data, changedData);
|
||||
|
||||
await fs.ensureFile(data_file);
|
||||
await fs.writeJson(data_file, data);
|
||||
path_exists = true;
|
||||
|
||||
changedData = {};
|
||||
|
||||
await fs.ensureFile(configFile);
|
||||
await fs.writeJson(configFile, data);
|
||||
configFileExists = true;
|
||||
|
||||
console.log("Window bounds have been successfully saved!");
|
||||
} catch(error) {
|
||||
console.warn("Failed to save window bounds: %o", error);
|
||||
}
|
||||
console.log("Window bounds have been successfully saved!");
|
||||
}
|
||||
|
||||
let path_exists = undefined;
|
||||
export async function get_last_bounds(key: string) : Promise<Rectangle> {
|
||||
let configFileExists: boolean;
|
||||
export async function loadLastWindowsBounds(key: string) : Promise<Rectangle | undefined> {
|
||||
try {
|
||||
if(typeof(path_exists) === "undefined" ? !(path_exists = await fs.pathExists(data_file)) : !path_exists) {
|
||||
throw "skip!";
|
||||
if(typeof configFileExists !== "boolean") {
|
||||
configFileExists = await fs.pathExists(configFile);
|
||||
}
|
||||
|
||||
const data = await fs.readJson(data_file) || {};
|
||||
if(data[key]) {
|
||||
if(!configFileExists) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const data = await fs.readJson(configFile) || {};
|
||||
if(typeof data[key] === "object") {
|
||||
return data[key];
|
||||
}
|
||||
} catch(error) {
|
||||
if(error !== "skip!") {
|
||||
console.warn("Failed to load window bounds for %s: %o", key, error);
|
||||
}
|
||||
console.warn("Failed to load window bounds for %s: %o", key, error);
|
||||
}
|
||||
|
||||
return {
|
||||
height: undefined,
|
||||
width: undefined,
|
||||
x: undefined,
|
||||
y: undefined
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function startTrackWindowBounds(windowId: string, window: BrowserWindow) {
|
||||
@ -59,57 +56,68 @@ export function startTrackWindowBounds(windowId: string, window: BrowserWindow)
|
||||
|
||||
const onWindowBoundsChanged = () => {
|
||||
changedData[windowId] = window.getBounds();
|
||||
if(window.isMaximized()) {
|
||||
changedData[windowId].width = -1;
|
||||
changedData[windowId].height = -1;
|
||||
}
|
||||
|
||||
clearTimeout(changedDataSaveTimeout);
|
||||
changedDataSaveTimeout = setTimeout(save_changes, 1000) as any;
|
||||
changedDataSaveTimeout = setTimeout(saveChanges, 1000) as any;
|
||||
};
|
||||
|
||||
for(const event of events)
|
||||
for(const event of events) {
|
||||
window.on(event as any, onWindowBoundsChanged);
|
||||
}
|
||||
|
||||
window.on('closed', () => {
|
||||
for(const event of events)
|
||||
for(const event of events) {
|
||||
window.removeListener(event as any, onWindowBoundsChanged);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function loadWindowBounds(windowId: string, window: BrowserWindow, bounds?: Rectangle, options?: { applySize?: boolean; applyPosition?: boolean }) {
|
||||
export async function loadWindowBounds(windowId: string, window: BrowserWindow, targetBounds?: Rectangle, options?: { applySize?: boolean; applyPosition?: boolean }) {
|
||||
const screen = electron.screen || electron.remote.screen;
|
||||
|
||||
if(!bounds) {
|
||||
bounds = await get_last_bounds(windowId);
|
||||
let maximize = false;
|
||||
targetBounds = Object.assign({}, targetBounds || await loadLastWindowsBounds(windowId));
|
||||
|
||||
let originalBounds = window.getBounds();
|
||||
if(typeof options?.applySize === "boolean" && !options?.applySize) {
|
||||
targetBounds.width = originalBounds.width;
|
||||
targetBounds.height = originalBounds.height;
|
||||
}
|
||||
|
||||
if(!options) {
|
||||
options = {};
|
||||
if(typeof options?.applyPosition === "boolean" && !options.applyPosition) {
|
||||
targetBounds.x = originalBounds.x;
|
||||
targetBounds.y = originalBounds.y;
|
||||
}
|
||||
|
||||
const original_bounds = window.getBounds();
|
||||
|
||||
if(typeof(options.applySize) !== "boolean" || options.applySize) {
|
||||
let height = bounds.height > 0 ? bounds.height : original_bounds.height;
|
||||
let width = bounds.width > 0 ? bounds.width : original_bounds.width;
|
||||
|
||||
if(height != original_bounds.height || width != original_bounds.width)
|
||||
window.setSize(width, height, true);
|
||||
}
|
||||
|
||||
if(typeof(options.applyPosition) !== "boolean" || options.applyPosition) {
|
||||
let x = typeof(bounds.x) === "number" ? bounds.x : original_bounds.x;
|
||||
let y = typeof(bounds.y) === "number" ? bounds.y : original_bounds.y;
|
||||
|
||||
if(x != original_bounds.x || y != original_bounds.y) {
|
||||
const display = screen.getDisplayNearestPoint({ x: x, y: y });
|
||||
if(display) {
|
||||
const bounds = display.workArea || display.bounds;
|
||||
let flag_invalid = false;
|
||||
flag_invalid = flag_invalid || bounds.x > x || (bounds.x + bounds.width) < x;
|
||||
flag_invalid = flag_invalid || bounds.y > x || (bounds.y + bounds.height) < y;
|
||||
if(!flag_invalid) {
|
||||
window.setPosition(x, y, true);
|
||||
console.log("Updating position for %s", windowId);
|
||||
}
|
||||
}
|
||||
if(targetBounds.width < 0 || targetBounds.height < 0) {
|
||||
/* Invalid bounds or may -1 and -1 for max window */
|
||||
const nearestScreen = screen.getDisplayNearestPoint({ x: targetBounds.x + 30, y: targetBounds.y + 30 });
|
||||
if(nearestScreen) {
|
||||
maximize = true;
|
||||
targetBounds = Object.assign({}, nearestScreen.workArea);
|
||||
} else {
|
||||
targetBounds.width = originalBounds.width;
|
||||
targetBounds.height = originalBounds.height;
|
||||
}
|
||||
}
|
||||
|
||||
if(originalBounds.x === targetBounds.x &&
|
||||
originalBounds.y === targetBounds.y &&
|
||||
originalBounds.width === targetBounds.width &&
|
||||
originalBounds.height === targetBounds.height) {
|
||||
/* no changes */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Test if screen will be fully off display */
|
||||
/* FIXME: TODO! */
|
||||
|
||||
window.setBounds(targetBounds, true);
|
||||
if(maximize) {
|
||||
window.maximize();
|
||||
}
|
||||
}
|
@ -202,13 +202,13 @@ inline bool check_uuid(std::string& uuid, uint32_t check_sum) {
|
||||
return result == check_sum;
|
||||
}
|
||||
|
||||
static std::string _cached_system_uuid{};
|
||||
static uint32_t _cached_system_uuid_cksm = 0;
|
||||
static std::string cached_system_uuid_{};
|
||||
static uint32_t cached_system_uuid_cksm_ = 0;
|
||||
std::string system_uuid() {
|
||||
if(!_cached_system_uuid.empty() && check_uuid(_cached_system_uuid, _cached_system_uuid_cksm))
|
||||
return _cached_system_uuid;
|
||||
if(!cached_system_uuid_.empty() && check_uuid(cached_system_uuid_, cached_system_uuid_cksm_))
|
||||
return cached_system_uuid_;
|
||||
|
||||
if(!generate_uuid(_cached_system_uuid, _cached_system_uuid_cksm))
|
||||
_cached_system_uuid = "";
|
||||
return _cached_system_uuid;
|
||||
if(!generate_uuid(cached_system_uuid_, cached_system_uuid_cksm_))
|
||||
cached_system_uuid_ = "";
|
||||
return cached_system_uuid_;
|
||||
}
|
Loading…
Reference in New Issue
Block a user