Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: associate .alva files on macOS (#517)
Browse files Browse the repository at this point in the history
* feat: associate .alva files

* fixup! move file open to will-finish-launching

* fix: open file also on startup

* fixup! update document icon

* fix: restore auto update
  • Loading branch information
tilmx authored and marionebl committed Jun 5, 2018
1 parent 58c8910 commit a28d3e7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -68,6 +68,13 @@
"linux": {
"artifactName": "${productName}-${version}.${ext}",
"executableName": "Alva"
},
"fileAssociations": {
"ext": "alva",
"name": "Alva",
"icon": "document.icns",
"role": "Editor",
"isPackage": true
}
},
"standard-version": {
Expand Down
39 changes: 34 additions & 5 deletions src/electron/main.ts
Expand Up @@ -47,6 +47,8 @@ const writeFile = Util.promisify(Fs.writeFile);
// be closed automatically when the JavaScript object is garbage collected.
let win: BrowserWindow | undefined;

let openedFile: string | undefined;

let projectPath: string | undefined;

const userStore = new ElectronStore();
Expand Down Expand Up @@ -96,20 +98,24 @@ async function createWindow(): Promise<void> {
break;
}
case ServerMessageType.AppLoaded: {
// Load last known file automatically in development
if (electronIsDev && projectPath) {
const result = await Persistence.read<Types.SavedProject>(projectPath);
const pathToOpen = projectPath || openedFile;

// Load one of either
// (1) last known file automatically in development
// (2) file passed to electron main process
if (((electronIsDev && projectPath) || openedFile) && pathToOpen) {
const result = await Persistence.read<Types.SavedProject>(pathToOpen);

if (result.state === PersistenceState.Error) {
// TODO: Show user facing error here
} else {
const contents = result.contents as Types.SerializedProject;
contents.path = projectPath;
contents.path = pathToOpen;

send({
type: ServerMessageType.OpenFileResponse,
id: message.id,
payload: { path: projectPath, contents }
payload: { path: pathToOpen, contents }
});
}
}
Expand Down Expand Up @@ -457,6 +463,29 @@ async function createWindow(): Promise<void> {
const log = require('electron-log');
log.info('App starting...');

app.on('will-finish-launching', () => {
app.on('open-file', async (event, path) => {
event.preventDefault();
if (path) {
openedFile = path;

const result = await Persistence.read<Types.SavedProject>(path);

if (result.state === PersistenceState.Error) {
// TODO: Show user facing error here
} else {
const contents = result.contents as Types.SerializedProject;

Sender.send({
type: ServerMessageType.OpenFileResponse,
id: uuid.v4(),
payload: { path, contents }
});
}
}
});
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
Expand Down
Binary file added src/resources/document.icns
Binary file not shown.

0 comments on commit a28d3e7

Please sign in to comment.