Support modifying userChrome even if user hasn't done it themselves first

This commit is contained in:
Oliver Blanthorn 2018-04-28 00:08:39 +01:00
parent 5d178fce3a
commit 2f31ade76a
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 23 additions and 5 deletions

View file

@ -8,7 +8,7 @@ import struct
import subprocess
import tempfile
VERSION = "0.1.0"
VERSION = "0.1.1"
class NoConnectionError(Exception):
@ -91,8 +91,20 @@ def handleMessage(message):
reply['content'] = output
elif cmd == 'read':
with open(message["file"], "r") as file:
reply['content'] = file.read()
try:
with open(message["file"], "r") as file:
reply['content'] = file.read()
reply['code'] = 0
except FileNotFoundError:
reply['content'] = ""
reply['code'] = 2
elif cmd == 'mkdir':
os.makedirs(
os.path.relpath(message["dir"]), exist_ok=message["exist_ok"]
)
reply['content'] = ""
reply['code'] = 0
elif cmd == 'write':
with open(message["file"], "w") as file:

View file

@ -198,9 +198,11 @@ export async function guiset(rule: string, option: string) {
return
}
} else profile_dir = config.get("profiledir")
const cssstr = (await Native.read(profile_dir + "/chrome/userChrome.css")).content
await Native.mkdir(profile_dir + "/chrome", true)
let cssstr = (await Native.read(profile_dir + "/chrome/userChrome.css")).content
// this will get overwritten as soon as a second command is run.
await Native.write(profile_dir + "/chrome/userChrome.css.tri.bak", cssstr)
if (cssstr === "") cssstr = `@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");`
let stylesheet = CSS.parse(cssstr)
let stylesheetDone = CSS.stringify(css_util.changeCss(rule, option, stylesheet))
Native.write(profile_dir + "/chrome/userChrome.css", stylesheetDone)

View file

@ -8,7 +8,7 @@ import Logger from "./logging"
const logger = new Logger("native")
const NATIVE_NAME = "tridactyl"
type MessageCommand = "version" | "run" | "read" | "write" | "temp"
type MessageCommand = "version" | "run" | "read" | "write" | "temp" | "mkdir"
interface MessageResp {
cmd: string
version: number | null
@ -146,6 +146,10 @@ export async function write(file: string, content: string) {
return sendNativeMsg("write", { file, content })
}
export async function mkdir(dir: string, exist_ok: boolean) {
return sendNativeMsg("mkdir", { dir, exist_ok })
}
export async function temp(content: string) {
return sendNativeMsg("temp", { content })
}