Skip to content

Commit

Permalink
Disable TypeScript by default (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp authored Oct 4, 2024
1 parent e5c077b commit 8128951
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions data/app.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<key name="first-run" type="b">
<default>true</default>
</key>
<key name="typescript" type="b">
<default>false</default>
</key>
</schema>
<schema id="@[email protected]" path="/re/sonny/Workbench/">
<key name="show-code" type="b">
Expand Down
8 changes: 7 additions & 1 deletion src/Extensions/Extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Interface from "./Extensions.blp" with { type: "uri" };
import illustration from "./extensions.svg";

import "./Extension.js";
import { getFlatpakInfo } from "../util.js";
import { getFlatpakInfo, settings } from "../util.js";

export const action_extensions = new Gio.SimpleAction({
name: "extensions",
Expand Down Expand Up @@ -34,6 +34,7 @@ export function Extensions({ window }) {

extension_typescript.available = isTypeScriptAvailable();
extension_typescript.command = `flatpak install flathub org.freedesktop.Sdk.Extension.${node}//${freedesktop_version} org.freedesktop.Sdk.Extension.typescript//${freedesktop_version}`;
extension_typescript.visible = isTypeScriptEnabled();

for (const extension of [
extension_rust,
Expand Down Expand Up @@ -71,6 +72,7 @@ export function isValaAvailable() {
let typescript_available = null;
export function isTypeScriptAvailable() {
typescript_available ??=
isTypeScriptEnabled() &&
Gio.File.new_for_path("/usr/lib/sdk/typescript").query_exists(null) &&
Gio.File.new_for_path(`/usr/lib/sdk/${node}`).query_exists(null);
return typescript_available;
Expand All @@ -80,3 +82,7 @@ const llvm = "llvm18";
const node = "node20";
const runtime = getFlatpakInfo().get_string("Application", "runtime");
const freedesktop_version = runtime.endsWith("master") ? "24.08" : "24.08";

export function isTypeScriptEnabled() {
return settings.get_boolean("typescript");
}
5 changes: 4 additions & 1 deletion src/Library/Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
needsAdditionalPermissions,
showPermissionsDialog,
} from "../Permissions/Permissions.js";
import { isTypeScriptEnabled } from "../Extensions/Extensions.js";

export default function Library({ application }) {
const objects = build(resource);
Expand Down Expand Up @@ -75,8 +76,10 @@ export default function Library({ application }) {
{ id: "python", name: _("Python"), index: 2 },
{ id: "rust", name: _("Rust"), index: 3 },
{ id: "vala", name: _("Vala"), index: 4 },
{ id: "typescript", name: _("TypeScript"), index: 5 },
];
if (isTypeScriptEnabled()) {
languages.push({ id: "typescript", name: _("TypeScript"), index: 5 });
}
const languages_by_id = Object.fromEntries(
languages.map((language) => [language.id, language]),
);
Expand Down
10 changes: 1 addition & 9 deletions src/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,7 @@ Adw.ApplicationWindow window {
}

DropDown dropdown_code_lang {
model: StringList {
strings [
"JavaScript",
"Vala",
"Rust",
"Python",
"TypeScript",
]
};
model: StringList {};

tooltip-text: _("Switch Document");
}
Expand Down
9 changes: 9 additions & 0 deletions src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
Extensions,
isRustAvailable,
isTypeScriptAvailable,
isTypeScriptEnabled,
isValaAvailable,
} from "./Extensions/Extensions.js";
import { Permissions } from "./Permissions/Permissions.js";
Expand Down Expand Up @@ -70,6 +71,14 @@ export default function Window({ application, session }) {
});
Permissions({ window });

const dropdown_code_lang = builder.get_object("dropdown_code_lang");
for (const lang of ["JavaScript", "Vala", "Rust", "Python"]) {
dropdown_code_lang.model.append(lang);
}
if (isTypeScriptEnabled()) {
dropdown_code_lang.model.append("TypeScript");
}

// Popover menu theme switcher
const button_menu = builder.get_object("button_menu");
const popover = button_menu.get_popover();
Expand Down

0 comments on commit 8128951

Please sign in to comment.