Skip to content

Commit

Permalink
oops
Browse files Browse the repository at this point in the history
  • Loading branch information
WamWooWam committed Jun 4, 2021
1 parent 6157c91 commit 10f1fa9
Show file tree
Hide file tree
Showing 4,515 changed files with 669,970 additions and 68,817 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*

*.winmd
*.dll
*.pri
*.exe

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down Expand Up @@ -44,6 +49,9 @@ jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

B3B9BB81.56264F78B4FFF/
zeptolabuklimited.cuttherope/

# TypeScript cache
*.tsbuildinfo

Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"args" : ["."],
"args" : [".", "winstore/Windows.Store"],
"outputCapture": "std"
}
]
Expand Down
223,828 changes: 223,828 additions & 0 deletions gen/Windows.ts

Large diffs are not rendered by default.

86 changes: 66 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { app, protocol, BrowserWindow, shell, ipcMain } from "electron"
import { app, protocol, BrowserWindow, shell, ipcMain, session } from "electron"
const path = require("path")
const fs = require('fs')
const rename = require('deep-rename-keys')

const E_NOTFOUND = -6;
const supportedLanguages = ["generic", "en", "en-gb", "en-us"]; // slightly different to speed up accessing generic resources
const supportedLanguages = ["generic", "scale-100", "scale-80", "en", "en-gb", "en-us"]; // slightly different to speed up accessing generic resources
const packageResourcesMap: Map<string, Map<string, any>> = new Map();

protocol.registerSchemesAsPrivileged([{ scheme: 'ms-appx', privileges: { standard: true, secure: true, bypassCSP: true } }])
protocol.registerSchemesAsPrivileged([{
scheme: 'ms-appx', privileges: {
standard: true,
secure: true,
bypassCSP: true,
allowServiceWorkers: true,
supportFetchAPI: true
}
}])

function loadResourcesForPackage(resourcesPath: any, packageName: string) {
if (packageResourcesMap.has(packageName)) {
Expand Down Expand Up @@ -36,35 +44,51 @@ function loadResourcesForPackage(resourcesPath: any, packageName: string) {
return languages;
}

function lookupResource(pathName: string, resourceMap: Map<string, any>): string {
function lookupInJson(json: any, subsplits: string[], name: string) {
for (const split of subsplits) {
if (json === undefined || split == null || split == "")
continue;

json = json[split];
}

if (json === undefined)
return null;

return json[name];
}

function lookupResource(pathName: string, resourceMap: Map<string, any>, properties: URLSearchParams): string {
let resource = null;
let splits = pathName.toLowerCase().split("/");
let subsplits = ["files", ...splits.slice(0, splits.length - 1)];
let name = splits[splits.length - 1];

for (const language of resourceMap) {
let json = language[1];
for (const split of subsplits) {
if (json === undefined || split == null || split == "")
continue;
if (properties.has("scale")) {
let key = "scale-" + properties.get("scale");
console.log(key);

if (resourceMap.has(key)) {
var data = resourceMap.get(key);

json = json[split];
if ((resource = lookupInJson(data, subsplits, name)) !== null)
return resource;
}
}

if (json === undefined)
continue;
for (const language of resourceMap) {
let json = language[1];

resource = json[name];
break;
if ((resource = lookupInJson(json, subsplits, name)) !== null)
return resource;
}

return resource;
}

function appxUriHandler(request: any, callback: any) {
let url = new URL(request.url);
let packageName = url.host;
let pathName = url.pathname;
let pathName = decodeURI(url.pathname);
let query = url.searchParams;

// find the root of the package
let dirName = path.join(__dirname, "..");
Expand Down Expand Up @@ -95,7 +119,7 @@ function appxUriHandler(request: any, callback: any) {

// load the resource map, and lookup the resource (case insensitive)
let resourceMap = loadResourcesForPackage(resourcesPath, packageName);
let resource = lookupResource(pathName, resourceMap);
let resource = lookupResource(pathName, resourceMap, query);

if (resource) { // if we find it, return it
filePath = path.join(packagePath, resource.replace(/\\/g, "/"));
Expand All @@ -114,17 +138,39 @@ function appxUriHandler(request: any, callback: any) {
}

app.allowRendererProcessReuse = true;
app.commandLine.appendSwitch('enable-experimental-web-platform-features')

const filePath = path.join(app.getPath('appData'), "app-launch-flags.txt")
if (fs.existsSync(filePath)) {
let args = fs.readFileSync(filePath, "utf-8");
for (const arg of args.split(',')) {
app.commandLine.appendSwitch(arg);
}
}

app.whenReady().then(() => {
protocol.registerFileProtocol("ms-appx", appxUriHandler);
protocol.registerFileProtocol("ms-appx-web", appxUriHandler);
protocol.registerFileProtocol('file', (request, callback) => {
const pathname = decodeURIComponent(request.url.replace('file:///', ''));
callback(pathname);
});

session.defaultSession.webRequest.onBeforeSendHeaders({ urls: ["*://*.discord.com/", "*://*.discord.gg/"] }, (details, callback) => {
details.requestHeaders['User-Agent'] = 'DiscordBot (https://github.com/WamWooWam/WinRTElectron, 1.0.0)';
callback({ cancel: false, requestHeaders: details.requestHeaders });
});


let win = new BrowserWindow({
width: 1366,
height: 788,
width: 1440,
height: 900,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
webviewTag: true,
webSecurity: false, // fuck you.
contextIsolation: false,
enableRemoteModule: true,
},
autoHideMenuBar: true,
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
"node-fetch": "^2.6.0"
},
"devDependencies": {
"electron": "^10.1.2",
"electron-packager": "^15.0.0",
"typescript": "^3.9.2"
"electron": "^12.0.2",
"electron-builder": "^22.10.5",
"electron-packager": "^15.2.0",
"postcss": "^8.2.8",
"postcss-cli": "^8.3.1",
"postcss-html": "^0.36.0",
"postcss-prettify": "^0.3.4",
"postcss-syntax": "^0.36.2",
"postcss-unprefix": "^2.1.4",
"typescript": "^4.3.2"
},
"scripts": {
"start": "electron ."
Expand Down
2 changes: 2 additions & 0 deletions packages/microsoft.bing/AppxBlockMap.xml

Large diffs are not rendered by default.

Loading

0 comments on commit 10f1fa9

Please sign in to comment.