mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Support modifying userChrome even if user hasn't done it themselves first
This commit is contained in:
parent
5d178fce3a
commit
2f31ade76a
3 changed files with 23 additions and 5 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue