-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix supranet.connected, global paths
- Loading branch information
Showing
9 changed files
with
88 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Pointer } from "../runtime/pointers.ts"; | ||
import { client_type } from "../utils/constants.ts"; | ||
let onlineStatus: Pointer<boolean> | undefined = undefined; | ||
|
||
export function getOnlineState() { | ||
if (!onlineStatus) | ||
onlineStatus = Pointer.createOrGet<boolean>(navigator?.onLine ?? true); | ||
if (client_type === "deno") { | ||
// TODO | ||
} | ||
else { | ||
globalThis.addEventListener("online", () => onlineStatus!.val = true); | ||
globalThis.addEventListener("offline", () => onlineStatus!.val = false); | ||
} | ||
return onlineStatus; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
import { client_type } from "../utils/constants.ts"; | ||
import { cwdURL } from "../utils/global_values.ts"; | ||
import { projectRootURL } from "../utils/global_values.ts"; | ||
import { normalizePath } from "../utils/normalize-path.ts"; | ||
import { commandLineOptions } from "../utils/args.ts"; | ||
|
||
let custom_cache_path = commandLineOptions.option("cache-path", {aliases: ["c"], type: "string", description: "Overrides the default path for datex cache files (.datex-cache)"}) | ||
|
||
let _cache_path:string|URL = new URL('./.datex-cache/', cwdURL); | ||
let _ptr_cache_path:string|URL = new URL('./pointers/', _cache_path); | ||
export async function _updateCachePaths() { | ||
|
||
// command line args (--watch-backend) | ||
if (client_type == "deno") { | ||
let _cache_path:string|URL = new URL('./.datex-cache/', projectRootURL); | ||
let _ptr_cache_path:string|URL = new URL('./pointers/', _cache_path); | ||
|
||
const commandLineOptions = (await import("../utils/args.ts" /*lazy*/)).commandLineOptions | ||
|
||
let custom_cache_path = commandLineOptions.option("cache-path", {aliases: ["c"], type: "string", description: "Overrides the default path for datex cache files (.datex-cache)"}) | ||
|
||
if (custom_cache_path) { | ||
if (custom_cache_path?.startsWith("/")) custom_cache_path = `file://${custom_cache_path}`; | ||
if (!custom_cache_path?.endsWith("/")) custom_cache_path += '/'; | ||
// command line args (--watch-backend) | ||
if (client_type == "deno") { | ||
|
||
if (custom_cache_path) { | ||
_cache_path = new URL(custom_cache_path, cwdURL); | ||
if (custom_cache_path?.startsWith("/")) custom_cache_path = `file://${custom_cache_path}`; | ||
if (!custom_cache_path?.endsWith("/")) custom_cache_path += '/'; | ||
if (custom_cache_path) { | ||
_cache_path = new URL(custom_cache_path, projectRootURL); | ||
_ptr_cache_path = new URL('./pointers/', _cache_path); | ||
} | ||
} | ||
|
||
// check if write permission for configured datex cache dir | ||
|
||
try { | ||
const testUrl = new URL("write_test", _cache_path.toString()); | ||
Deno.mkdirSync(normalizePath(testUrl), {recursive: true}) | ||
Deno.removeSync(testUrl); | ||
} | ||
catch { | ||
const prev = _cache_path; | ||
_cache_path = new URL(normalizePath(await Deno.makeTempDir()+"/"), "file:///"); | ||
_ptr_cache_path = new URL('./pointers/', _cache_path); | ||
console.log("(!) cache directory "+prev+" is readonly, using temporary directory " + _cache_path); | ||
} | ||
} | ||
|
||
// check if write permission for configured datex cache dir | ||
|
||
try { | ||
const testUrl = new URL("write_test", _cache_path.toString()); | ||
Deno.mkdirSync(normalizePath(testUrl), {recursive: true}) | ||
Deno.removeSync(testUrl); | ||
} | ||
catch (e) { | ||
const prev = _cache_path; | ||
_cache_path = new URL(normalizePath(await Deno.makeTempDir()+"/"), "file:///"); | ||
_ptr_cache_path = new URL('./pointers/', _cache_path); | ||
console.log("(!) cache directory "+prev+" is readonly, using temporary directory " + _cache_path); | ||
} | ||
cache_path = _cache_path; | ||
ptr_cache_path = _ptr_cache_path; | ||
} | ||
|
||
export const cache_path = _cache_path; | ||
export const ptr_cache_path = _ptr_cache_path; | ||
export let cache_path: URL; | ||
export let ptr_cache_path: URL; | ||
|
||
await _updateCachePaths(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters