Skip to content

Commit

Permalink
registerFileProtocolの離脱 (#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Jul 30, 2023
1 parent da73bcd commit 123413c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
44 changes: 15 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"@vue/test-utils": "2.3.0",
"cross-env": "7.0.3",
"cross-var": "1.1.0",
"electron": "23.3.10",
"electron": "25.3.2",
"electron-builder": "24.0.0-alpha.12",
"electron-devtools-installer": "3.2.0",
"eslint": "8.24.0",
Expand Down
18 changes: 10 additions & 8 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Menu,
shell,
nativeTheme,
net,
} from "electron";
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
import Store, { Schema } from "electron-store";
Expand Down Expand Up @@ -128,17 +129,10 @@ if (isDevelopment) {
__static = __dirname;
}

// ソフトウェア起動時はプロトコルを app にする
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true, stream: true } },
]);
if (process.env.VITE_DEV_SERVER_URL == undefined) {
// FIXME: registerFileProtocolが非推奨になったので対策を考える
protocol.registerFileProtocol("app", (request, callback) => {
const filePath = new URL(request.url).pathname;
callback(path.join(__dirname, filePath));
});
}

const firstUrl = process.env.VITE_DEV_SERVER_URL ?? "app://./index.html";

// 設定ファイル
Expand Down Expand Up @@ -495,6 +489,14 @@ async function createWindow() {
}
}

// ソフトウェア起動時はプロトコルを app にする
if (process.env.VITE_DEV_SERVER_URL == undefined) {
protocol.handle("app", (request) => {
const filePath = new URL(request.url).pathname;
return net.fetch(`file://${filePath}`);
});
}

await loadUrl({ projectFilePath });

if (isDevelopment && !isTest) win.webContents.openDevTools();
Expand Down
2 changes: 2 additions & 0 deletions src/background/engineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ export class EngineManager {

if (engineProcess === undefined)
throw Error("engineProcess === undefined");
if (engineProcess.pid === undefined)
throw Error("engineProcess.pid === undefined");

engineProcess.once("close", restartEngineOnProcessClosedCallback);

Expand Down

0 comments on commit 123413c

Please sign in to comment.